1.刚创建好的空仓库的分支是空的,即使是master分支也是不存在的。master分支是不能通过git branch 来创建的,只有在完成第一次提交才会自动创建,有git自动完成master分子的创建,也就是只有第一次提交创建好master分支后,才能再创建别的分支。因为git本质上就是基于图论原理的,图的第一个起点是系统在第一次提交的时候自动创建的,别的创建的所有的都是其他的分支都是第一个master分支后的“分支”。master作为主分支,在所有的git项目都是固定。所有的git项目都有master主分支,分分支则是不确定的。

harvey@harvey-Virtual-Machine:~/demo3$ git init ../demo4 #创建一个新的空仓库
Initialized empty Git repository in /home/harvey/demo4/.git/
harvey@harvey-Virtual-Machine:~/demo3$ cd ../demo4
harvey@harvey-Virtual-Machine:~/demo4$ echo "fsf">tes #创建新文件t
harvey@harvey-Virtual-Machine:~/demo4$ git add ./ #添加到缓存区
harvey@harvey-Virtual-Machine:~/demo4$ git branch#打印branch 列表发现为空,即使master分支也不存在
harvey@harvey-Virtual-Machine:~/demo4$ git branch master#手动创建master分支失败
fatal: Not a valid object name: 'master'.
harvey@harvey-Virtual-Machine:~/demo4$ git branch 分支#手动创建"分支"分支失败
fatal: Not a valid object name: 'master'.
harvey@harvey-Virtual-Machine:~/demo4$ git commit ./#第一次提交commit(隐式的创建master分支)
[master (root-commit) eca4197] sfsf:wq
1 file changed, 1 insertion(+)
create mode 100644 test
harvey@harvey-Virtual-Machine:~/demo4$ git branch#打印master分支发现分支创建成功
* master
harvey@harvey-Virtual-Machine:~/demo4$ git branch 分支#再次创建“分支”分支
harvey@harvey-Virtual-Machine:~/demo4$ git branch#再打印branch发现列表有数据了
* master
分支

2.没有完成第一次提交也就是没有创建master分支的时候,是不能checkout master的因为没有master分支存在。这个时候,只能使用的是checkout . 命令,因为checkout .的意思就是把缓存区的数据覆盖工作空间.在没有创建提交的时候,可以用点代表全部的缓冲区文件,也可以用git checkout –<file>检出单独的文件。可以认为缓冲区stage就是也个目录,我们的checkout就是从stage这个目录把数据拷贝到当前工作的目录。而commit就是把stage这个文件夹再做单独的备份,备份从原理上也是在master这个主文件下,如果还是单个的子文件夹就是单独分支,如果在master后创建了新的分支就如同创建了新的文件夹。git其实也正是一个文件系统。

harvey@harvey-Virtual-Machine:~$ rm -r -f demo4
harvey@harvey-Virtual-Machine:~$ git init demo4
Initialized empty Git repository in /home/harvey/demo4/.git/
harvey@harvey-Virtual-Machine:~$ cd demo4
harvey@harvey-Virtual-Machine:~/demo4$ echo "tttt">test
harvey@harvey-Virtual-Machine:~/demo4$ git add ./
harvey@harvey-Virtual-Machine:~/demo4$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: test
#
harvey@harvey-Virtual-Machine:~/demo4$ rm test #清空工作空间,这时候工作空间是空的
harvey@harvey-Virtual-Machine:~/demo4$ git checkout master#checkou master失败
error: pathspec 'master' did not match any file(s) known to git.
harvey@harvey-Virtual-Machine:~/demo4$ git checkout . #checkout . 用工作空间的数据
harvey@harvey-Virtual-Machine:~/demo4$ ls#发现从缓存位置取出了缓存的数据
test

3.基于我们认为stage是和工作空间相同的工作目录,历史提交也是工作空间,也就是文件夹。那么我们就可以用diff命令来比较的时候,本质上也是不叫的文件夹。

harvey@harvey-Virtual-Machine:~$ rm -r -f demo4
harvey@harvey-Virtual-Machine:~$ git init demo4
Initialized empty Git repository in /home/harvey/demo4/.git/
harvey@harvey-Virtual-Machine:~$ cd demo4
harvey@harvey-Virtual-Machine:~/demo4$ mkdir a/a/
mkdir: 无法创建目录"a/a/": 没有那个文件或目录
harvey@harvey-Virtual-Machine:~/demo4$ mkdir a/a/ -p
harvey@harvey-Virtual-Machine:~/demo4$ echo "test1">a.txt #创建第一级别的文本文件
harvey@harvey-Virtual-Machine:~/demo4$ echo "test1">a/a/a.txt#创建文件夹下的文本文件
harvey@harvey-Virtual-Machine:~/demo4$ git add ./
harvey@harvey-Virtual-Machine:~/demo4$ git diff #提交在比较,因为此时两个文件夹是同步了的,所以diff没有输出内容,也就是两个文件夹没有差别
harvey@harvey-Virtual-Machine:~/demo4$ echo "ttttt">>a.txt #更改文件
harvey@harvey-Virtual-Machine:~/demo4$ echo "ttttt">>a/a/a.txt #更改文件
harvey@harvey-Virtual-Machine:~/demo4$ git diff #发现输出的内容是比较的两个文件的差异,所以是比较的是文件夹
diff --git a/a.txt b/a.txt
index a5bce3f..9f42087 100644
--- a/a.txt
+++ b/a.txt
@@ -1 +1,2 @@
test1
+ttttt
diff --git a/a/a/a.txt b/a/a/a.txt
index a5bce3f..9f42087 100644
--- a/a/a/a.txt
+++ b/a/a/a.txt
@@ -1 +1,2 @@
test1
+ttttt #发现git diff的文件比较顺序是 ”diff stage 工作空间“
harvey@harvey-Virtual-Machine:~/demo4$ git status -s #发现第一个A表示HEAD是空的,M表示stage和工作空间比较内容变化了,具体的变化内容只能通过diff来查看。也就是status显示的是摘要
AM a.txt
AM a/a/a.txt

git学习笔记二-branch分支的更多相关文章

  1. Git学习笔记 (二)

    Git学习笔记(二) 突然发现,学习新知识新技能,都得经常温故使用,这样才能日益精进.最近学习的Git是因为加入了课题组,在学习做一些后台,由于后台开发会牵扯到多人开发,所以学会Git这一代码管理工具 ...

  2. git 学习笔记 —— 获取远端分支并修改后提交至远端仓库

    笔者最近进行开发过程中,所有参与者的代码需要通过 git 上传到远端仓库中,不同的模块对应不同的 git 分支,不同模块的数据需要从远端仓库中获取.这里记录下笔者从远端仓库中获取分支数据,进行修改,最 ...

  3. git学习笔记06-创建分支合并分支-比svn快多了,因为只有指针在改变

    一开始git只有一条时间线,这个分支叫主分支,即master分支. HEAD严格来说不是指向提交,而是指向master,master才是指向提交的,所以,HEAD指向的就是当前分支. 每次提交,mas ...

  4. Git学习笔记二--工作区和暂存区

    Git和其他版本控制系统如SVN的一个不同之处就是有暂存区的概念. 简单理解: 我们使用mkdir Git在d盘下创建的文件夹,就是工作区,我们编辑readme.txt文件就是在工作区下完成的: gi ...

  5. Git学习笔记(二) 远程仓库及分支

    添加远程仓库(以GitHub为例) 所谓的远程仓库,其实就和本地仓库一样,只是我们本地电脑可能会关机什么的.远程仓库的目的就是保证7*24小时开启状态.GitHub是一个很好的公共Git远程仓库(后面 ...

  6. GIT学习笔记(4):远程分支

    GIT学习笔记(4):远程分支 远程分支 远程分支是什么 远程分支是对远程仓库中的分支的索引.它们是一些无法移动的本地分支:只有在GIT进行网络交互时才会更新.远程分支就是书签,提醒着你上次连接远程仓 ...

  7. GIT学习笔记(3):分支管理

    GIT学习笔记(3):分支管理 何谓分支 GIT是如何存储数据的 GIT不是存储文件差异或者变化量,而是一系列文件的快照.在Git提交时,会保存一个提交(commit)对象,该对象包含一个指向暂存内容 ...

  8. Git学习笔记(二) · 非典型性程序猿

    远程库的使用 前面说到的都是git在本地的操作,那么实际协作开发过程中我们肯定是要有一个远程版本库作为项目的核心版本库,也就是投入生产使用的版本.这里我们以 Github为例.Github是一个开放的 ...

  9. Git学习笔记与IntelliJ IDEA整合

    Git学习笔记与IntelliJ IDEA整合 一.Git学习笔记(基于Github) 1.安装和配置Git 下载地址:http://git-scm.com/downloads Git简要使用说明:h ...

随机推荐

  1. powerdesigner 点击preview 语句出现 if exists

    drop table if exists XXX 这个是sql server 写法.如果要切换为 Oracle 写法 菜单栏: database-->change curren DBMS 选择你 ...

  2. BZOJ3173:[TJOI2013]最长上升子序列 & HDU3564:Another LIS——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=3173 http://acm.hdu.edu.cn/showproblem.php?pid=3564 ...

  3. [bzoj] 1588 营业额统计 || Splay板子题

    原题 给出一个n个数的数列ai ,对于第i个元素ai定义\(fi=min(|ai-aj|) (1<=j<i)\),f1=a1,求\(/sumfi\) Splay板子题. Splay讲解:h ...

  4. Static全局变量与普通的全局变量有什么区别?static函数与普通函数有什么区别?

    Static全局变量与普通的全局变量有什么区别? 答: 全局变量(外部变量)的说明之前再冠以static就构成了静态的全局变量.全局变量本身就是静态存储方式,静态全局变量当然也是静态存储方式. 这两者 ...

  5. 【简单算法】17.字符串转整数(atoi)

    题目: 实现 atoi,将字符串转为整数. 在找到第一个非空字符之前,需要移除掉字符串中的空格字符.如果第一个非空字符是正号或负号,选取该符号,并将其与后面尽可能多的连续的数字组合起来,这部分字符即为 ...

  6. 第三方库安装——lxml

    环境 操作系统:CentOS 6.7 32-bit Python:2.6.6 安装 安装依赖软件 yum -y install gcc make python-devel libxml2-devel ...

  7. Qt error ------ 出现Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly

    出现原因: 使用了不存在的对象 数组越界了 用 delete 释放未分配的内存空间,或者超过一次释放同个内存 比如: 顺序不能颠倒 正确: ui->setupUi(this); ui->t ...

  8. Sublime Text 配置python文件

    每次配置Sublime Text的都是好一顿搜索配置信息,今天特地把自己电脑上配置好的信息保存下来,方便以后使用. 用到了 AutoPEP8.Anaconda.SublimeCodeIntel.Sub ...

  9. git设置免密码登录

    设置用户名和邮箱 git config --global user.name "<username>" git config --global user.email & ...

  10. 【CODEVS】1281 Xn数列

    [算法]矩阵快速幂 [题解]T*A(n-1)=A(n)矩阵如下: a 1 * x(n-1) 0 = xn 0 0 1    c        0    c   0 防止溢出可以用类似快速幂的快速乘. ...