1

現在のプロジェクトで git ツリーに本当に奇妙な状況があります。

fileで、次から変更したa.txtid= を commitしました。my_new_contents_commit

old contents
old contents
old contents

に:

old contents
old contents
old contents
my new contents

同時に (このコミットをマージすることなく)、他のチーム メンバーがいくつかの変更を行いました。それから彼は私の変更をプルし、id= をマージしましたinteresting_merge(彼は "tower" と呼ばれる 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 がこのように奇妙に見えない方法でマージされたことをどのように確認できますか?

ありがとうございました!

4

1 に答える 1

2

git show多くの親コミットがあるコミットの差分は表示されません。git は表示すべきN差分 (N親コミットの数はどこにあるのか) がわからないためです。

競合を手動で解決すると、この diff はコミット メッセージ内に存在するだけで、それ以上のことはありません。

それはどのように可能ですか?

簡単。このマージ コミットmy new contentsでは、単に削除されます。次の 2 つの差分のいずれかで見つける必要があります。

  • マージコミットとその最初の親コミットとの差分
  • マージ コミットとその 2 番目の親コミットとの差分

最後に、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が、差分の 1 つでわかるように変更されています。

$> 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
于 2013-05-16T20:12:35.430 に答える