1

I am merging a branch in a project that uses git submodules. Usually when there is a conflict there are two sets of changes, theirs and ours. Resolving the conflicts is about merging these two into one. But I noticed that for git submodules the diff shows a third value:

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

What do the "- ", " -" and "++' mean?

Note that it's possible that the submodule version actually checked out in the repository before the merge was neither theirs nor ours, would that explain the three hashes?

Greg
  • 8,230
  • 5
  • 38
  • 53

1 Answers1

1

It simply means the submodule gitlink (the special entry in the index of the parent repo) was changed both in source and destination.
(See git diff man page)

++ means one line that was added does not appear in either branch1 or branch2

From Git Tools - Advanced Merging:

You have three SHA1 because in a conflict, Git stores all of these versions in the index under “stages” which each have numbers associated with them.

  • Stage 1 is the common ancestor,
  • stage 2 is your version and
  • stage 3 is from the MERGE_HEAD, the version you’re merging in (“theirs”).

The combined diff format section has all the details:

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".

In your case:

  • A - in the first column means file1, meaning stage 2, meaning "ours" version.
  • A - in the second column mean file2, meaning stage 3, meaning "theirs".
  • A '++' means an addition which was not in file1 or 2 (each time when compared with the common ancestor from stage 1)
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • What does it mean that it changed in source? Comparing to what? Local changes? In this particular example which SHA1 is ours, with "- " or " -"? – Greg Dec 15 '16 at 07:29
  • @Amiramix comparing to the common ancestor. – VonC Dec 15 '16 at 07:30
  • @Amiramix See https://git-scm.com/docs/git-diff#_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"). – VonC Dec 15 '16 at 07:34
  • OK, but when git shows the two deletions and one addition it doesn't say which deletion version is coming from which stage difference. It only shows "- " and " -". Would it consistently associate "- " with the difference between stage 1 and stage 3 for example (or between stage 1 and stage 2)? – Greg Dec 15 '16 at 07:48
  • @Amiramix yes, the output remains consistent for any merge. – VonC Dec 15 '16 at 07:51
  • Sure, but which is which? I mean, which one of the "- " and " -" is for which difference (stage 1 to 2 and 1 to 3)? – Greg Dec 15 '16 at 08:16
  • @Amiramix from the doc: "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": so a `-` in the first column means file1, meaning stage 2, meaning "ours" version. A `-` in the second column mean file2, meaning stage 3, meaning "theirs". A '`++`' means an addition which was not in file1 or 2 (each time when compared with the common ancestor from stage 1) – VonC Dec 15 '16 at 08:24
  • Great, that's going to be a handy reference. – Greg Dec 15 '16 at 08:31