git show
不显示与许多父提交的提交的差异,因为 git 不知道它应该显示什么N
差异(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
,将其添加到 staging with git add a.txt
,添加 staging 以提交,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