visual-git-guide备忘
内容来自:http://marklodato.github.com/visual-git-guide/index-en.html
什么是reference: reference,引用指的都是.git下的文件。
HEAD就是reference中的一个, HEAD的指向的都是current branch。
注意branch上面箭头表示可以移动到任意一个commit的id上。commit的箭头表示指向parent commit对象。
理解了reference之后,对于reset也很好理解。The reset command moves the current branch to another position。比如下图的操作表示将当前分支沿着指针指向,向ancestor移动三次。
git merge的操作中,针对Fast Forward情况有move reference的操作。
git merge 源分支,该命令的含义是把源分支的内容合并的目标分支上或者当前分支上(也就是current branch上) 比如git merge master表示要将master分支合并到current branch上来。注意,合并的结果是HEAD指向了current branch。
merge有false,true二种merge:
1) “false merge”
a.如果源分支是current branch的ancestor,那么do nothing。(current branch已经是最新的了,所以什么都不做)
b.如果current branch是源分支的ancestor,那么只做reference的move,这称为fast forward.下面是fast forward的情况。(current branch是源分支的祖先,也就意味着current branch旧,源分支新。 将新合并到旧的结果是新建了一个commit。同时将当前分支与源分支都指向这个commit)
2)“true merge”,也就是Non Fast Forward的情况出现时的merge。这种merge一般不鼓励的。因为一个commit会指向二个parent,这样的做法是导致non line-history出现。
可选多种merge策略。默认是recursive策略。
a.原理:three-way merge,而不再是简单的do nothing或者fast merge. 注意三路对应的是哪三路:takes the current commit (ed489 below), the other commit (33104), and their common ancestor (b325c), and performs a three-way merge.
b.特点:会产生一个新的commit对象。
Otherwise, a "real" merge must occur. You can choose other strategies, but the default is to perform a "recursive" merge, which basically takes the current commit (ed489 below), the other commit (33104), and their common ancestor (b325c), and performs a three-way merge. The result is saved to the working directory and the stage, and then a commit occurs, with an extra parent (33104) for the new commit.
git merge other表示将other分支做为源分支合并到current branch-master上。
当three-way merge制造了non-line history时,git rebase通过人为的调整顺序将当前分支的提交内容放到了最后
rebase的定义:
A rebase is an alternative to a merge for combining multiple branches. Whereas a merge creates a single commit with two parents, leaving a non-linear history, a rebase replays the commits from the current branch onto another, leaving a linear history. In essence, this is an automated way of performing several cherry-picks in a row.
git rebase master类似于git merge master表达的语义,表示将master分并到current branch上。(current branch已经由上图的master变成了下图的topic)
下面是需要merge或rebase的场景:
Afterward, maint is no longer an ancestor of master. To join the two histories, a merge (or rebase) will be necessary. A rebase is an alternative to a merge for combining multiple branches.