2011-05-20 49 views
8

在下面的例子中,有沒有辦法知道發生了合併?看着git日誌,我不能說我合併了。如何檢查git日誌以進行「快進」合併?

# setup example directory 
$ mkdir test 
$ cd test 
$ git init 
$ touch a 
$ git add a 
$ git commit -m "1" 

# switch to different branch 
$ git checkout -b topic 
$ touch b 
$ git add b 
$ git commit -m "2" 

# go back to master and merge 
$ git checkout master 
$ git merge topic 

# git log 

commit cccc64de3947828f487a8ce3c3e72b0f68dc88c3 
Author: none 
Date: Fri May 20 05:54:45 2011 -0700 

    2 

commit a5d57454295759609d91a60219002e74016eed2b 
Author: none 
Date: Fri May 20 05:54:29 2011 -0700 

    1 

回答

12

在這種情況下,混帳已經發現,它可能做一個所謂的「快進」合併,因爲你歸併的分支已經包含在當前分支一切 - 它不需要在提交圖中創建一個新的提交以加入兩個分支。

如果你不喜歡這種行爲,並希望建立一個合併提交,即使快速轉發是可能的,你應該在另一分支與合併:

git merge --no-ff topic 

但是,如果你真的需要知道是否發生了合併,您可以在「reflog」中找到該信息。例如,在您的情況,git reflog會產生以下的輸出:

1eecbcb [email protected]{0}: merge topic: Fast-forward 
193ae5e [email protected]{1}: checkout: moving from topic to master 
1eecbcb [email protected]{2}: commit: 2 
193ae5e [email protected]{3}: checkout: moving from master to topic 
193ae5e [email protected]{4}: commit (initial): 1 

...這表明你HEAD怎麼最近變了,什麼樣的行動造成這樣的事情發生。然而,依賴於reflog通常是一個糟糕的主意,除非在特定的情況下,比如從錯誤中恢復 - 最好是從提交圖的角度思考,並且讓它代表你所做的。 git merge --no-ff就是很多人喜歡的一種方法。

+0

謝謝,這是有益的。看起來像git reflog只顯示我的本地活動。我正在使用GitHub--是否有辦法知道其他人是否進行了快速合併? – Ravi 2011-05-20 13:26:21

+0

@suravi否,除非他們告訴你。快進合併就像沒有合併一樣。 – hobbs 2011-05-20 13:33:19

+0

感謝它非常有幫助,但正如你所說的,當兩個分支代碼都是一樣的時候,快進合併就會發生嗎? – Aabid 2016-03-10 09:35:09

0

如果你想嘗試一下,你有一個真正的合併的情況下,你可以git checkout master後運行以下命令:

touch c 
git add c 
git commit -m "3" 
git merge topic 

也就是說,您添加提交到主分支。然後,提交圖不再是線性序列,數據必須從多個分支合併。

1

還可以使用Git的合併基礎:

git merge-base master topic 

它將顯示cccc64de3947828f487a8ce3c3e72b0f68dc88c3(2)提交

或者你可以使用:

git show $(git merge-base master topic) 
+0

找出_where_合併發生的好方法,但對_if_沒有多大幫助,因爲在這種情況下,您不知道主題分支的名稱。 – 2011-05-20 14:11:59