Basic Branching and Merging
两种合并的情况:Fast-forward
,merge-commit
1. Fast-forward
快进
when you try to merge one commit with a commit that can be reached by following the first commit’s history, Git simplifies things by moving the pointer forward because there is no divergent work to merge together — this is called a “fast-forward.”
如下:将hotfix
分支合并到master
分支上,只是将master
分支上的指针向前移了一下。
$ git checkout master
$ git merge hotfix
Updating f42c576..3a0874c
Fast-forward
index.html | 2 ++
1 file changed, 2 insertions(+)
2. merge commit
合并提交
Instead of just moving the branch pointer forward, Git creates a new snapshot that results from this three-way merge and automatically creates a new commit that points to it. This is referred to as a merge commit, and is special in that it has more than one parent
如下图:将iss53
分支合并到master
分支,三方合并生成一个新的提交(合并提交)。
$ git checkout master
Switched to branch 'master'
$ git merge iss53
Merge made by the 'recursive' strategy.
index.html | 1 +
1 file changed, 1 insertion(+)
注意:遇到冲突,要把冲突解决了,再手动 stage、commit