合并的git-diff中最后一行的双号加号 [英] Double plus sign for the last line in git-diff of merge

查看:153
本文介绍了合并的git-diff中最后一行的双号加号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git合并期间的简单冲突情况。
例如:

  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
++> gt>>>>>>> br2

我感兴趣的是为什么在每个分支块的末尾我们有如下行:

  +8 
+9
- newnewnew
++ newnewnew

但不只是

  +8 
+9
+ newnewnew

谢谢。

解决方案

TL; DR



合并冲突需要请用户判断哪一方应该做什么。

看来双加号线表示有问题的部分结束 - 因为它是合并冲突双方同意应该添加到最终合并产品中的一条线。



长版本令人惊讶的是,我找不到任何有价值的文档,但它似乎是一种适用于合并冲突差异显示的语法 - 至少是这样的是我见过这种情况的唯一位置。



我认为它基于git diff语法,我会解释:
当git执行合并时,它会尝试将文件A合并到文件B.如果有冲突,因为git希望用户做最少的工作,它会创建一个部分合并(work-in-progress )文件C,然后要求用户通过将A和B放在两边来完成合并,并让用户决定C应该如何查看。



在这种情况下,这意味着有3个文件被区分开来,并且每行需要一个语法来显示所有3之间的关系。因此,我们没有超过2个状态的行,这取决于合并是否决定将它输入合并(C)文件。



双加表示该行存在于A和B中,但目前不在C中,这是一个很好的提示它应该在C中,但合并出于某种原因无法做出选择来添加它。



所以diff的两个第一列的负数和正数只是表示该行是否缺失,存在或添加到右侧或左侧文件A和B中。

p $ p> 我的原始线1.

我的原始线2.

a唯一一条线。

a新的代码行



B:

 我的原始线1. 

我的原始线2.

a独特的B线。

a新代码行

C(partial-diff) p>

  my original line 1. 

my original line 2.

a new code行

可以说A被合并到B中以创建部分差异C。



统一差异窗口将显示如下所示:



(用正常空格取代0:当它既不是负号也不是加号)

  00my原始线1. 

00my原始线2.

+ 0a独特的A线。

0 +一条独特的B线。

++新的代码行

正如您所看到的,那就是在合并两边的文件中都标记为双加 - 表示双方同意这应该被添加,而其他人则说每个人都希望在里面添加不同的部分 - 这是提示到合并实际上失败的部分。

希望我帮了一下,为混乱的外观感到抱歉,我不善于使用语法..


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.

解决方案

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

这篇关于合并的git-diff中最后一行的双号加号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆