为什么合并这些分支没有任何作用?

Why does merging these branches do nothing?

短版:

我有两个不同内容的分支。当我在一个分支中并从另一个分支进行合并时,它显示 "Already up-to-date"。这怎么可能?

为了简单起见,我现在甚至没有进行拉取,只是从本地分支进行合并。

后面可能太详细了。

我将以一个特定的文件为例。在 branch master 中(我正在编辑电子邮件地址和较旧的提交):

$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

$ git log mde/ss/schools/_clone/segmeta.csv
commit 9e9ee2b19e7a476f2d61ecff1c5d54634132dd93
Author: gormleycep <redacted>
Date:   Mon Nov 23 11:18:41 2015 -0800

    Fixes spacing issues in segmeta files (my mistake)

commit 6e341cd2a92a1044c957a7a9631e365a08466440
Author: gormleycep <redacted>
Date:   Fri Nov 6 12:36:52 2015 -0800

    Updated percent positive tables

commit efc05d8b838fb3e8efdc074b65d1a93046c7e6c9
Author: Alan deLespinasse <redacted>
Date:   Tue Aug 11 18:46:42 2015 -0400

    Fix missing segmentations in MDE Secondary School reports.

在分支 BTP_E2ESCH:

$ git checkout BTP_E2ESCH
Checking out files: 100% (2330/2330), done.
M       common
Switched to branch 'BTP_E2ESCH'
Your branch is up-to-date with 'origin/BTP_E2ESCH'.

$ git log mde/ss/schools/_clone/segmeta.csv
commit 9367a601eef9a7a8975a0cf22d5b49b163a3710c
Author: cepbrian <redacted>
Date:   Fri Nov 13 16:17:49 2015 -0500

    trying to add end to end tests.

commit efc05d8b838fb3e8efdc074b65d1a93046c7e6c9
Author: Alan deLespinasse <redacted>
Date:   Tue Aug 11 18:46:42 2015 -0400

    Fix missing segmentations in MDE Secondary School reports.

cepbrian 在 11 月 13 日所做的更改与 gormleycep 在 11 月 6 日所做的更改相同(两次更改都向文件添加了相同的两行)。 gormleycep 在 11 月 23 日所做的更改删除了这两行中的空格。两个分支的文件肯定是不一样的。现在我做:

$ git merge master
Already up-to-date.

并且分支BTP_E2ESCH中的文件没有改变。

这里是 gitk --all --date-order mde/ss/schools/_clone/segmeta.csv 的输出,为了更容易可视化:

什么状态可以Git发生这种情况?

我认为 git log -- <filename> 的输出可能有点 欺骗性 的问题。来自 man git-log:

[--] ... Show only commits that are enough to explain how the files that match the specified paths came to be.

并重定向到 历史简化 部分,其中有很多细节...

我的意思是你的分支可能已经合并了,但是你在你的简化日志中看不到它!

这最好通过一个例子来理解。让我们考虑这个存储库:

A----B----C----M
     \----T----/

有分支的地方,test指向Tmaster指向M,这是合并提交。存储库中有一个 file,每次提交时的内容为:

A: 1
B: 2
C: 3
T: ttt
M: 3

test 合并到 master 时发生冲突,通过丢弃 T 的版本解决了这个问题。

现在,如果我从 mastergit log 运行,我得到:

M
C
T
B
A

但是如果我 运行 git log -- file,我得到:

C
B
A

因为 TM 提交对文件的最终内容没有影响。那就是历史简化

您可以 运行 git log --full-history -- test 获取涉及文件的所有提交:

M
C
T
B
A