Git文件更改不是';与冲突合并后在日志中看不到

Git文件更改不是';与冲突合并后在日志中看不到,git,Git,在我当前的项目中,我对git tree有着非常奇怪的情况 在文件a.txt中,我确实提交了id=my_new_contents_commit,将其从以下内容更改为: old contents old contents old contents 致: 同时(不合并此提交),其他团队成员做了一些更改。然后他拉了我的更改并合并了id=有趣的\u merge(他使用了一些称为“tower”的git工具)git show对于该合并提交,显示如下内容: ➤ git show interesting_mer

在我当前的项目中,我对git tree有着非常奇怪的情况

在文件
a.txt
中,我确实提交了id=
my_new_contents_commit
,将其从以下内容更改为:

old contents
old contents
old contents
致:

同时(不合并此提交),其他团队成员做了一些更改。然后他拉了我的更改并合并了id=
有趣的\u 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是以一种如此奇怪、毫无表情的方式合并的呢


谢谢大家!

git show
不显示具有多个父提交的提交的差异,因为git不知道应该显示哪些
N
差异(其中
N
是父提交的数量)

当您手动解决一些冲突时,此差异仅存在于提交消息中,仅此而已

怎么可能呢

简单。在这个合并提交中,我的新内容被删除。您应该在以下两个差异之一中找到它:

  • 合并提交与其第一个父级提交之间的差异
  • 合并提交与其第二个父级提交之间的差异
最后,
git diff SHA^应该很有用


如何做到这一点

假设我们有两个提交

$> 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
他试图推它,结果被拒绝了:[

$> 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(+)
这是一条提交消息,类似于jws的
合并分支“master”:~/test
。然后他编辑文件
a.txt
,用
git add a.txt将其添加到staging中,用
git commit将staging添加到提交中--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 commit--amend
或其他方法删除。你可以这样做要知道,合并提交只是许多父提交的常见提交,而合并提交消息中的冲突差异只是一个文本-它不是自动计算的差异。小心!(对不起,我理解关于--amend的评论,但问题是它已经被推送,所以我认为它不会有帮助)我仍然不明白,在自动合并过程中,如果没有任何冲突,如何删除单个(只有一个特定的)文件的更改。好的,我现在了解了你的情况。我认为很可能他只是在编辑器打开时使用了一个旧内容的.txt文件(这几乎不可能,因为他通常对python文件不感兴趣),然后保存它,将内容改写为旧状态。我没有看到他使用的GUI,但我会问他是否可能放了“-amend”不管怎么说,这听起来还是很奇怪和不可能的,但至少感谢你们提供了关于分别查看这两个合并差异的提示,我现在相信没有什么变化了。
$> 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(+)
$> 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
$> 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