Mercurial 相邻行合并冲突

发布于 2024-11-16 03:41:43 字数 775 浏览 0 评论 0原文

我发现了以下案例。

$ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一百个冬季 2024-11-23 03:41:43

Mercurial 无法自动合并,因为存在必须由人类解决的冲突。 Mercurial 应该如何知道合并版本是否应包含

line 1
line 21

line 11
line 2

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文