Git 筆記 (8-2) git Fast-forward merge

git Fast-forward merge


1. 先架設一個測試用環境:

$ mkdir Git
$ cd Git
$ touch test.py
$ git init
$ git add .
$ git commit -m "First commit"

2. 在 HEAD 要產生 debug 分支,並對 debug 進行兩次 commit:

$ git checkout -b debug   # 產生並切換至 debug 分支
$ cp test.py test2.py
$ git add .
$ git commit -m "Add test2.py" 

$ cp test.py test3.py
$ git add .
$ git commit -m "Add test3.py" 
$ gitk --all






3. 在 debug 合併 master 看看 (在 master 合併 debug 會有相同結果):

$ git checkout debug     # 確認是在 debug 分支
$ git merge master
$ gitk --all

這種類似把 master 快轉到 debug 的現象稱為 Fast-forward



4. 在 merge 時使用 --no-ff 可以避免 Fast-forward:

$ git checkout master     # 確認是在 master 分支
$ git merge --no-ff debug
$ gitk --all

讓 master 往上長:

留言

熱門文章