合并子模块时的三个提交引用

Three commit references when merging submodules

我正在合并一个使用 git 子模块的项目中的分支。通常当有冲突时会有两组变化,他们的和我们的。解决冲突就是将这两者合而为一。但我注意到对于 git 子模块,diff 显示第三个值:

diff --cc my_submodule
index dd7404e,e6753b1..0000000
--- a/my_submodule
+++ b/my_submodule
@@@ -1,1 -1,1 +1,1 @@@
- Subproject commit dd7404e5f35ee0b0064f0d6ed8201cc39d6ed6b2
 -Subproject commit e6753b1142cf0350608720ff23f7ecf51b813cd9
++Subproject commit 3b4e75fbb7c55cf21e19509bbbbfabfa1fc10630

“-”、“-”和“++”是什么意思?

请注意,合并之前在存储库中签出的子模块版本可能既不是他们的也不是我们的,这可以解释三个哈希值吗?

这只是意味着子模块 gitlink (the special entry in the index of the parent repo) 在源和目标中都被更改了
(参见 git diff man page

++ 表示添加的一行没有出现在 branch1 或 branch2

来自 Git Tools - Advanced Merging:

你有三个 SHA1,因为在冲突中,Git 将所有这些版本存储在“阶段”下的索引中,每个阶段都有与之关联的数字。

  • 第 1 阶段是共同祖先,
  • 第 2 阶段是您的版本,
  • 第 3 阶段来自 MERGE_HEAD,您要合并的版本(“他们的”)。

combined diff format 部分包含所有详细信息:

When shown by git diff-files -c (combined diff of merged files), it compares the two unresolved merge parents with the working tree file

I.e.

  • file1 is stage 2 aka "our version",
  • file2 is stage 3 aka "their version".

A - character in the column N means that the line appears in fileN but it does not appear in the result.
A + character in the column N means that the line appears in the result, and fileN does not have that line".

你的情况:

    第一列的
  • 一个-表示file1,表示stage 2,表示"ours"版本。
  • 第二列中的一个-表示file2,表示阶段3,表示"theirs"。
  • A '++' 表示不在 file12 中的加法(每次与阶段 1 的共同祖先进行比较时)