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

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

问题描述

维基百科说,三向合并的错误较少-比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.

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

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.

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

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