Mercurial 相邻行合并冲突
我发现了以下案例。
$ 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
结果:
合并file.txt失败!
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
如果我们尝试上述场景,但有 3 行,并且更改位于第 1 行和第 2 行,则合并将成功。 那么,我的问题为什么会发生这种情况?这是合并算法的问题还是其他问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Mercurial 无法自动合并,因为存在必须由人类解决的冲突。 Mercurial 应该如何知道合并版本是否应包含
或
Mercurial 不将合并的一侧视为可以优先的权威。
file.txt
中的标记是 Mercurial 为您提供哪些地方需要您动手的提示。但是,您可以通过配置交互式合并工具 用于冲突。另请查看此相关问题。
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
or
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.