GNU diff3(三向合并)给出了意想不到的结果

发布于 2024-09-27 13:52:12 字数 565 浏览 3 评论 0原文

假设文件 MINE 和 YOURS 是 OLD 的后代。

FILE_MINE=

abc
def
ghi

FILE_OLD=

abc
jkl
ghi

FILE_YOURS=

abc
def
ghi

命令 diff3 -m MIND OLD YOURS 给出:

abc
<<<<<<< OLD
jkl
=======
def
>>>>>>> YOURS
ghi

diff3 无法解析 MINE 和 YOURS 所做的相同更改。

为什么?并且,有办法解决这个问题吗?

用这个来刺激你的大脑:

diff OLD MINDdiff OLD YOURS 在它们的输出中有相同的块。

2c2
< jkl
---
> def

在三路合并期间,这些猛男不应该“取消”吗?

Assume that files MINE and YOURS are descendants of OLD.

FILE_MINE=

abc
def
ghi

FILE_OLD=

abc
jkl
ghi

FILE_YOURS=

abc
def
ghi

Command diff3 -m MIND OLD YOURS gives:

abc
<<<<<<< OLD
jkl
=======
def
>>>>>>> YOURS
ghi

diff3 cannot resolve that MINE and YOURS made identical changes.

Why? And, is there a way to resolve this issue?

Tickle your brain with this:

diff OLD MIND and diff OLD YOURS have identical hunks in their output.

2c2
< jkl
---
> def

Should these hunks not "cancel-out" during the three-way merge?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

妄想挽回 2024-10-04 13:52:12

你期望得到什么?

正如描述 diff3 实用程序的文章所说:

...当所有三个输入文件不同或仅较旧的文件不同时,此(合并)不成立;我们称之为冲突。当所有三个输入文件都不同时,我们将冲突称为重叠

因此,您所描述的情况将被视为冲突。 “为什么会这样呢?”你可能会问。因为diff3算法。您可以在同一页面找到说明:

您可以将此(合并)视为从您的中减去较旧的并将结果添加到我的中,或者合并到我的中那些会让你变老的改变

它无法正确解决差异,因为它没有进行更改的适当背景。

如果您要说它应该使用其他方法来工作,我会同意您的观点。但是……事情就是这样。 diff3 并不完美,如果您想按照文章

What did you expect to have?

As the article describing diff3 utility says:

... This (merging) fails to be true when all three input files differ or when only older differs; we call this a conflict. When all three input files differ, we call the conflict an overlap

Therefore, the case you've described is treated as a conflict. 'Why so?' you might ask. Because of the diff3 algorithm. Description you can find at the same page:

You can think of this (merging) as subtracting older from yours and adding the result to mine, or as merging into mine the changes that would turn older into yours

It cannot resolve differences properly because it does not have a proper context of changes being made.

I would agree with you if you're going to say that it should work using some other approach. But... it is what it is. diff3 is not perfect, I would recommend using other tools if you want to do it right as described in the article

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