git学习笔记二-branch分支
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分支的更多相关文章
- Git学习笔记 (二)
Git学习笔记(二) 突然发现,学习新知识新技能,都得经常温故使用,这样才能日益精进.最近学习的Git是因为加入了课题组,在学习做一些后台,由于后台开发会牵扯到多人开发,所以学会Git这一代码管理工具 ...
- git 学习笔记 —— 获取远端分支并修改后提交至远端仓库
笔者最近进行开发过程中,所有参与者的代码需要通过 git 上传到远端仓库中,不同的模块对应不同的 git 分支,不同模块的数据需要从远端仓库中获取.这里记录下笔者从远端仓库中获取分支数据,进行修改,最 ...
- git学习笔记06-创建分支合并分支-比svn快多了,因为只有指针在改变
一开始git只有一条时间线,这个分支叫主分支,即master分支. HEAD严格来说不是指向提交,而是指向master,master才是指向提交的,所以,HEAD指向的就是当前分支. 每次提交,mas ...
- Git学习笔记二--工作区和暂存区
Git和其他版本控制系统如SVN的一个不同之处就是有暂存区的概念. 简单理解: 我们使用mkdir Git在d盘下创建的文件夹,就是工作区,我们编辑readme.txt文件就是在工作区下完成的: gi ...
- Git学习笔记(二) 远程仓库及分支
添加远程仓库(以GitHub为例) 所谓的远程仓库,其实就和本地仓库一样,只是我们本地电脑可能会关机什么的.远程仓库的目的就是保证7*24小时开启状态.GitHub是一个很好的公共Git远程仓库(后面 ...
- GIT学习笔记(4):远程分支
GIT学习笔记(4):远程分支 远程分支 远程分支是什么 远程分支是对远程仓库中的分支的索引.它们是一些无法移动的本地分支:只有在GIT进行网络交互时才会更新.远程分支就是书签,提醒着你上次连接远程仓 ...
- GIT学习笔记(3):分支管理
GIT学习笔记(3):分支管理 何谓分支 GIT是如何存储数据的 GIT不是存储文件差异或者变化量,而是一系列文件的快照.在Git提交时,会保存一个提交(commit)对象,该对象包含一个指向暂存内容 ...
- Git学习笔记(二) · 非典型性程序猿
远程库的使用 前面说到的都是git在本地的操作,那么实际协作开发过程中我们肯定是要有一个远程版本库作为项目的核心版本库,也就是投入生产使用的版本.这里我们以 Github为例.Github是一个开放的 ...
- Git学习笔记与IntelliJ IDEA整合
Git学习笔记与IntelliJ IDEA整合 一.Git学习笔记(基于Github) 1.安装和配置Git 下载地址:http://git-scm.com/downloads Git简要使用说明:h ...
随机推荐
- POJ2549:Sumsets——题解
http://poj.org/problem?id=2549 题目大意:从集合中找到四个不相同的数,满足a+b+c=d,输出最大的d. —————————————————————————— 该式子变为 ...
- BZOJ1257:[CQOI2007]余数之和——题解+证明
http://www.lydsy.com/JudgeOnline/problem.php?id=1257 Description 给出正整数n和k,计算j(n, k)=k mod 1 + k mod ...
- 【BZOJ 4555】[Tjoi2016&Heoi2016]求和 多项式求逆/NTT+第二类斯特林数
出处0.0用到第二类斯特林数的性质,做法好像很多,我打的是直接ntt,由第二类斯特林数的容斥公式可以推出,我们可以对于每一个i,来一次ntt求出他与所有j组成的第二类斯特林数的值,这个时候我们是O(n ...
- Tomcat启动时报org.springframework.web.context.ContextLoaderListener错误解决方案
问题现象:新从svn上检出maven的项目maven+spring+springmvc项目在Tomcat启动时,报如下错误. 严重: Error configuring application lis ...
- oracle数据库解锁
当我们修改数据库时用for update 或者使用rowId修改后,对表进行了锁定,由于某种原因没有对他进行关闭,我们需要关闭 select b.username,b.sid,b.serial#,lo ...
- [技巧篇]21.Android Studio的快捷键设置[图片版]
如果对你有帮助,请点击推荐!
- [LeetCode] 大数问题,相加和相乘,题 Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- springboot线程池@Async的使用和扩展
我们常用ThreadPoolExecutor提供的线程池服务,springboot框架提供了@Async注解,帮助我们更方便的将业务逻辑提交到线程池中异步执行,今天我们就来实战体验这个线程池服务: 本 ...
- 51Nod 1014 X^2 Mod P
注意潜在范围 x*x用long long #include <bits/stdc++.h> using namespace std; typedef long long LL; #defi ...
- Ubuntu12.04 SVN安装过程
一.安装SVN和配置SVN 1.安装SVN apt-get install subversion 2.创建SVN目录,项目目录和配置文件目录 mkdir /var/svn mkdir /var/svn ...