简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM