为什么 3 路合并优于 2 路合并? [英] Why is a 3-way merge advantageous over a 2-way merge?

查看:32
本文介绍了为什么 3 路合并优于 2 路合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

维基百科说三路合并错误更少- 比 2 路合并更容易,而且通常不需要用户干预.为什么会这样?

Wikipedia says a 3-way merge is less error-prone than a 2-way merge, and often times doesn't need user intervention. Why is this the case?

一个 3 路合并成功而 2 路合并失败的例子会很有帮助.

An example where a 3-way merge succeeds and a 2-way merge fails would be helpful.

推荐答案

假设您和您的朋友都检查了一个文件,并对其进行了一些更改.您在开头删除了一行,而您的朋友在结尾添加了一行.然后他提交了他的文件,您需要将他的更改合并到您的副本中.

Say you and your friend both checked out a file, and made some changes to it. You removed a line at the beginning, and your friend added a line at the end. Then he committed his file, and you need to merge his changes into your copy.

如果您进行双向合并(换句话说,差异),该工具可以比较两个文件,并查看第一行和最后一行不同.但是它怎么知道如何处理这些差异呢?合并版本是否应该包括第一行?是否应该包括最后一行?

If you were doing a two-way merge (in other words, a diff), the tool could compare the two files, and see that the first and last lines are different. But how would it know what to do with the differences? Should the merged version include the first line? Should it include the last line?

通过三向合并,它可以比较两个文件,但也可以将它们中的每一个与原始副本(在您更改文件之前)进行比较.因此它可以看到您删除了第一行,而您的朋友添加了最后一行.它可以使用该信息来生成合并版本.

With a three-way merge, it can compare the two files, but it can also compare each of them against the original copy (before either of you changed it). So it can see that you removed the first line, and that your friend added the last line. And it can use that information to produce the merged version.

这篇关于为什么 3 路合并优于 2 路合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆