2013-05-16 36 views
1

我在當前項目中使用git樹時出現了非常奇怪的情況。合併衝突後未在日誌中看到Git文件更改

在文件a.txt,我確實犯ID = my_new_contents_commit,改變它:

old contents 
old contents 
old contents 

要:

old contents 
old contents 
old contents 
my new contents 

同時(不合並這個承諾),其他團隊成員做了一些改變。然後他拉我的變化,並確實合併id = interesting_merge(他使用一些稱爲「塔」的git工具)。 git show對於合併提交節目是這樣的:

➤ git show interesting_merge 
commit interesting_merge 
Merge: some_commit my_commit_with_new_contents_being_there 
Author: _ 
Date: Thu May 16 19:55:27 2013 +0300 

    Merge branch 'master' of _ 

    Conflicts: 
     static/css/style.css 

因此,似乎有合併過程中的一些矛盾,我不知道他們是如何得到解決。有趣的是,合併之後,文件又是舊版本。所以,如果你這樣做

➤ git checkout interesting_merge 
➤ cat a.txt 
old contents 
old contents 
old contents 

你會得到舊的內容。這怎麼可能?我怎麼能看到a.txt以這種奇怪的方式合併?

謝謝!

回答

2

git show不顯示DIFF與許多家長犯犯,因爲Git並不知道它應該顯示的N的diff(其中N是家長的數量提交)的內容。

當你通過手來解決一些衝突時,這個差異只存在於提交消息中,僅此而已。

這怎麼可能?

簡單。在這個合併提交my new contents剛剛被刪除。你應該有兩種差異列表中尋找它:合併之間

  • 差異承諾和它的第一個父提交
  • 合併之間的差異承諾和它的第二父提交

最後,git diff SHA^!應該是有用的。


它是如何做到的。

比方說我們有2款

$> git log --oneline 
30917b9 add my new contents 
d6a09ba add a.txt 

,最後提交類似於您

$> git show 
commit 30917b94b6e6740cacc854e891d67d29195b98c3 
Author: b <a> 
Date: Fri May 17 00:29:56 2013 +0400 

    add my new contents 

diff --git a/a.txt b/a.txt 
index 3be5d25..af49de6 100644 
--- a/a.txt 
+++ b/a.txt 
@@ -1,3 +1,4 @@ 
old contents 
old contents 
old contents 
+my new contents 

這時,有人做(d6a09ba)基礎上,第一次提交的變化:

commit f6997eae5f40f156897eedfbf058bcf3fe8730b6 
Author: b <a> 
Date: Fri May 17 00:34:38 2013 +0400 

    I don't care about new contents 

diff --git a/b.txt b/b.txt 
new file mode 100644 
index 0000000..d099a6a 
--- /dev/null 
+++ b/b.txt 
@@ -0,0 +1 @@ 
+well, this is a new file 

他試圖推動它,並得到拒絕:[

$> git push origin 
To jws:~/test.git 
! [rejected]  HEAD -> master (non-fast-forward) 

然後他拉你的承諾,並提出了合併

$> git pull origin master 
From jws:~/test 
* branch   master  -> FETCH_HEAD 
Merge made by the 'recursive' strategy. 
a.txt | 1 + 
1 file changed, 1 insertion(+) 

這是一個提交信息像Merge branch 'master' of jws:~/test。然後,他編輯的文件a.txt,將其添加到與git add a.txt分期,加分期git commit --amend,瞧承諾:

$> git show 
commit 51a3f94436cf1a9a763d84acfcf7202f9f2d88ec 
Merge: f6997ea 30917b9 
Author: b <a> 
Date: Fri May 17 00:36:56 2013 +0400 

    Merge branch 'master' of jws:~/test 

沒有關於a.txt的變化,但它被修改,因爲我們可以在差異文件,一見:

$> git diff 51a3f94436cf1a9a763d84acfcf7202f9f2d88ec^2 51a3f94436cf1a9a763d84acfcf7202f9f2d88ec 
diff --git a/a.txt b/a.txt 
index af49de6..3be5d25 100644 
--- a/a.txt 
+++ b/a.txt 
@@ -1,4 +1,3 @@ 
old contents 
old contents 
old contents 
-my new contents 
diff --git a/b.txt b/b.txt 
new file mode 100644 
index 0000000..d099a6a 
--- /dev/null 
+++ b/b.txt 
@@ -0,0 +1 @@ 
+well, this is a new file 
+0

是的,但問題是:它現在怎麼可能在a.txt有衝突,但仍然從其父母的更改中刪除內容? –

+0

>簡單。在這個合併提交中,我的新內容剛剛被刪除 你是絕對正確的,謝謝。下一個問題:它怎麼會發生? –

+0

衝突可以通過'git commit --amend'或其他東西去除。正如你可能知道的,合併提交只是許多父母提交的通常提交,而合併提交的消息中的衝突差異只是一個文本 - 它不是一個自動計算的差異。謹防! –