秒懂Git分支的合併機制

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

更多討論:https://github.com/pluscai/use-git/issues/21

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章