开发者

Mercurial merge conflict on adjacent lines

I found following case.

$ hg init
$ echo '
> line 1
> line 2
> ' > file.txt
$ hg add file.txt
$ hg commit -m 'added'
$ echo '
> line 11
> line 2
> ' > file.txt
$ hg commit -m 'changed line 1'
$ hg update 0
$ echo '
> line 1
> line 21
> ' > file.txt
$ hg commit -m 'changed line 2'
$ hg merge 1

The result:

merging file.txt failed!

hg diff file.txt

diff -r b开发者_StackOverflow中文版c62305d407b file.txt
--- a/file.txt  Fri Jun 17 22:53:22 2011 +0300
+++ b/file.txt  Fri Jun 17 22:53:46 2011 +0300
@@ -1,4 +1,9 @@

+<<<<<<< local
line 1
line 21
+=======
+line 11
+line 2
+>>>>>>> other

If we try the above scenario, but with 3 lines and changes are on 1 and 2 line, the merge will succeed. So, my question why this is happenning? Is this is a issue with the merge algorithm or something else?


Mercurial just cannot merge automatically because there's a conflict a human has to resolve. How should Mercurial know if the merged version should contain

line 1
line 21

or

line 11
line 2

Mercurial does not consider one side of the merge as an authority which could take precedence. The markers in file.txt are Mercurial's hints for you where your hands are needed.

However, you can avoid such in-file markers by configuring an interactive merge tool to be used on conflicts. Also have a look at this related question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜