git系列之(三)分支管理

(1)创建分支
git branch bra  创建一个bra分支(默认继承自master且master分支不能为空)
(2)创建基于分支
(3)查看分支
gitk --all 图形化查看分支图
(4)合并分支
git merge <brame>(将brname分支合并到当前分支,默认情形下采用Fast-forward方式合并)
(5)切换分支
git checkout <brname>(切换到brname分支)
git checkout -b <brname>(创建分支brname并切换到brname)

image

分支管理案例分析
假定有一个主分支master有两个文件m1.txt,m2.txt,在master上创建两个子分支A(bra),B(brb),此时bra,brb应该也有两文件m1.txt,m2.txt
场景一:假定切换到master分支加入m3.txt文件,则bra,brb是否可见?
    此时切换到bra,brb对于m3.txt是不可见的。
场景二:如果此时要将m3.txt对于bra分支可用如何操作?
    将分支切换到bra作为当前分支,git merge master,此时就可以看到m3.txt在bra分支中出现。此时的bra<=>master,可以删除bra。)

场景三:合并某分支指定文件到当前分支

使用git merge命令进行分支合并是通用的做法,但是git merge合并的时候会将两个分支的内容完全合并,如果想合并一部分肯定是不行的。那怎么办?如何从其他分支merge指定文件到当前分支,git checkout 是个合适的工具。

image

image
假定某一时候在master中添加了m4.txt,m5.txt两个文件,此时只希望将m4.txt更新到bra中,切换到bra分支后利用《git checkout master m4.txt》来达到目的(多个文件用空格分隔)。使用该指令前应该将当前分支切到bra。表明将master下的m4.txt文件合并至bra分支。
问题1:如果此时在bra版本中也有m4.txt则会将其完全覆盖,这并是我们想要的一种结果。
解决方案:

场景四:分支合并时同名文件
问题一:brb==>x.txt (已修改未提交状态)
假定在bra中有一个文件为x.txt,brb中也有一个x.txt,若brb中x.txt为修改未提交状态。此时用git merge bra不能合并
提示如下:
error: Your local changes to the following files would be overwritten by merge:x.txt
Please commit your changes or stash them before you merge.
Aborting
问题一:brb==>x.txt (已提交状态)
提示如下:
Auto-merging x.txt
CONFLICT (add/add): Merge conflict in x.txt
Automatic merge failed; fix conflicts and then commit the result.

(四)分支管理在项目管理中的应用案例分析:

如下图所示:有版本仓库share.git,创建了三个本地文件

image

image

参考资料:

http://www.cnblogs.com/-mrl/p/6648668.html

http://www.jianshu.com/p/5d34260824ee   【快速理解Git分支:合并】【2】

http://www.jianshu.com/p/893f159e28b0    【快速理解Git分支】【1】

http://www.jianshu.com/p/ce9fefaab751     【快速理解Git分支:变基】【3】

http://blog.csdn.net/wh_19910525/article/details/7554430   git cherry-pick 小结

git cat-file -t id:显示类型
git cat-file -p id:查看内容
git show id:查看内容
git ls-files --s
git log --stat
git log --pretty=raw --graph
git log --pretty=oneline
git diff
git diff head
git ls-tree head
git cherry-pick 57d2e76
git checkout

$ git checkout master
$ git merge --no-ff -m "merge with no-ff" bra
git merge-file -p
git diff-tree -p bra

分支里程碑

将所有commit的状态定义为C*
其他状态的定义为S*
重点监测点对象
HEAD
blob
index
commit
tree
parent
../master:

分支合并时文件
新增
删除
修改

原文地址:https://www.cnblogs.com/lihuali/p/7716355.html