2010-11-16 90 views
3

當我運行git的差異讓我比git的不同反饋合併

git diff FETCH_HEAD 

它列出的預期變化的負載,因爲我拿來從我的遠程更新的版本。

但....

當我運行

git merge FETCH_HEAD 

它告訴我一切是最新的!

我哪裏錯了?

+1

你有不分階段的變化?請'混帳status'。並嘗試'git的差異HEAD FETCH_HEAD',以避免與當前工作樹進行比較。 – 2010-11-16 09:58:11

+0

沒有提交,並且git diff HEAD FETCH_HEAD仍然給我很大的區別 – 2010-11-16 10:01:30

回答

2

爲什麼FETCH_HEADHEAD不同?合併後?

合併創建了一個新的提交,包含所有從原來的HEAD,現在ORIG_HEADFETCH_HEAD的變化。這意味着如果您的原始HEAD包含的變更未包含在FETCH_HEAD中,則新的(合併的)HEAD將與FETCH_HEAD不同,因爲它也包含這些提交。

事情檢查

這可能是您當前分支已經啓動最新與FETCH_HEAD從以前的獲取,由於上述原因,或因其他原因。

要從取頭檢查這一點,得到了sha(十六進制數),如下所示:

git log -1 FETCH_HEAD 
commit bec5aadef68a5d29c9d523358a0189b86cad4c82 
Author: Alex Brown <[email protected]> 
Date: Tue Nov 16 10:05:19 2010 +0000 

    weather report 

和複製的第一個6個位數的FETCH_HEADbec5aa

未來,搜索這個sha在你的頭上

git log HEAD | grep "commit bec5aa" -A 5 

commit bec5aadef68a5d29c9d523358a0189b86cad4c82 
Author: Alex Brown <[email protected]> 
Date: Tue Nov 16 10:05:19 2010 +0000 

    weather report 

如果這隻返回空白,FETCH_HEAD已被合併。您看到的任何差異都在當前的HEAD中,可能是合併的HEAD(或後代)。

*的例子來演示這個」

cd /tmp 
mkdir 1 
cd 1 
git init 
echo "Woo" > a.txt 
git add a.txt 
git commit -m "first commit" 
cd .. 
git clone 1 2 
cd 1 
echo "Its nice today" >> a.txt 
git commit -a -m "weather report" 
cd .. 
ls 
cd 2 
ls 
echo "Like peas in a pod" > b.txt 
git add b.txt 
git commit -m "sayings" 
git fetch 
git diff FETCH_HEAD 
git merge FETCH_HEAD 
git diff FETCH_HEAD 
+0

那麼你的意思是我的本地HEAD實際上超過了我的遠程FETCH_HEAD? – 2010-11-16 10:24:58

+1

要檢查你的'FETCH_HEAD'是否已經包含在'HEAD'中,你可以調用'git log HEAD..FETCH_HEAD',這將顯示'FETCH_HEAD'中的所有提交都沒有包含在'HEAD'中,如果輸出爲空,則沒有任何合併。使用像gitk這樣的圖形工具。 – 2010-11-16 10:38:26

+0

@MildFuzz - 這是你所看到的一種可能的解釋。 – 2010-11-16 10:43:31