Double plus sign for the last line in git-diff of merge

a 夏天 提交于 2019-12-14 02:18:41

问题


Simple conflict situation during git merge. E.g.:

index e910fdc,492c972..0000000
@@@ -1,10 -1,5 +1,18 @@@
++<<<<<<< HEAD
 +1
 +2
 +a
 +4
 +5
 +6
 +b
 +8
 +9
- newnewnew
++newnewnew
++=======
+ aa
+ aa
+ cc
+ aa
 -aa
++aa
++>>>>>>> br2

This is diff for not staged both modified file. I'm interested why at the end of each branch block we have lines like:

 +8
 +9
- newnewnew
++newnewnew

but not just

 +8
 +9
 +newnewnew

Thanks.


回答1:


TL;DR

a merge conflict needs to ask the user to judge which side should do what.

It seems the double plus sign line signifies the end of a problematic section - since it is a line BOTH sides of a merge conflict agree should be added into the final merge product.

Long Version

Amazing, I couldn't find any valuable documentation either, but it seems like this is a syntax meant for merge-conflict diff display - at least this is the only location where i've seen this happen.

I think it is based upon git diff syntax, and i will explain: when git performs a merge, it attempts to merge file A into file B. if there is a conflict, since git wants the user to do minimal work, it creates a partial-merge (work-in-progress) file C, and then asks the user to finish the merge by putting A and B on both sides, and letting the user decide how C should look in the end.

in this case, it means there are 3 files being diffed, and a syntax is required per line to show the relationship between all 3. so no we have more than 2 states for a line, depending on whether the merge decided to enter it into the merge (C) file.

a double plus just means that the line exists in both A and B, but is not in C currently, this is a good hint that it SHOULD be in C, but the merger for some reason couldn't make a choice to add it.

so the minus and plus on both 2 first columns of the diff just means whether the line is missing, existant, or added in the right or left files A and B.

here is a basic example:

A:

my original line 1.

my original line 2.

a unique A line.

a new code line

B:

my original line 1.

my original line 2.

a unique B line.

a new code line

C (the partial-diff):

my original line 1.

my original line 2.

a new code line

lets say A is merged into B to create the partial diff C.

The unified diff window will show something like this:

(replace 0 by a regular space: when its neither minus nor plus)

00my original line 1.

00my original line 2.

+0a unique A line.

0+a unique B line.

++a new code line

As you can see, the line that is in both files on both sides of the merge is marked as double plus - to say "both sides agree this should be added" while the other ones say "each wants a different part to be added inside" - and this is the hint to the section on which the merge actually failed.

Hope i helped a bit, sorry for the messy look, im not good at using the syntax yet..



来源:https://stackoverflow.com/questions/29976403/double-plus-sign-for-the-last-line-in-git-diff-of-merge

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!