为什么另一行的更改会引起git merge冲突? [英] Why changes in another line arise git merge conflict?
问题描述
我修改了不同分支中的不同行,但是这些更改发生在 git merge
冲突中.我读了帖子,但我认为更改发生在完全不同的线.
I modified different lines in different branches, but those changes occur git merge
conflict.
I read the post, but I think the changes occur in totally different lines.
这是我的测试代码.
Hello, my first conflict.
Second line.a # add a single character 'a' at line 2
Third line.
branch-a
Hello, my first conflict.
Second line.
Third line.a # add a single character 'a' at line 3
我执行了以下代码,它说git merge冲突.
And I executed the following code, it says git merge conflict.
$ git checkout branch-base
$ git merge branch-a
这是我的冲突文件.
Hello, my first conflict.
<<<<<<< HEAD
Second line.a
Third line.
=======
Second line.
Third line.a
>>>>>>> branch-a
为什么会发生这种冲突?我想我以完全不同的方式进行了更改(尽管它们是相邻的.)
Why this conflict happens? I think I made changes in totally different lines (although those are adjacent.)
推荐答案
必须至少有一条分隔线保持相同,以便可以将它们分开对待,而不会产生冲突.假设它们之间没有被在所有3个修订版(两个提示和共同祖先)上都保持相同的行分隔,则将它们视为一个单独的块.一个分支以一种方式修改该块,另一分支以另一种方式修改...因此,冲突.
There has to be at least a single line of separation that remains the same so that they can be treated separately and not produce a conflict. Given that they are not separated by a line that stays the same on all 3 revisions (the two tips and the common ancestor) then they are treated as a single block. One branch modifies that block one way, the other in another way... so, conflict.
这篇关于为什么另一行的更改会引起git merge冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!