git中的3-Way合并-比较工作原理 [英] 3-Way Merge in git - how comparing works

查看:216
本文介绍了git中的3-Way合并-比较工作原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有该文件的三个版本:

I have three versions of the file:

version 1       common ancestor      version  2
-------------   ---------------      ------------- 
before          original line        original line
original line                        after

在比较这些版本以生成最终合并版本时会发生什么?

What happens while comparing these versions to produce final merge version ?

我已经阅读了有关该主题的一些信息,但是我仍然对其工作原理感到困惑.

I have read some information about this topic, but I am still confused how exactly it works.

对于后面的示例:

是否正在比较线性版本之间的个别行? 如果是这样,则最终合并应如下所示:

Is comparing individual lines between versions linear ? If so, then final merge should look like this:

1 line: before
2 line: conflict (both left and right contributors are changed compared to ancestor) 

这是正确的理解,还是工作原理不同?

Is this correct understanding or does it work differently ?

推荐答案

三向合并通常意味着已经在查看通用的基本版本,而不仅仅是比较最终结果以执行合并.然后Git要做的是为每个版本创建更改的表示形式.

A three-way merge usually means that instead of just comparing the final result to perform the merge, the common base version is already being looked at. What Git then does is create a representation of changes for each version.

因此,相对于基本版本,它实际得到的是以下内容:

So what it actually gets, relative to the base version, is the following:

version 1           version  2
-------------       -------------
+before              original line
 original line      +after

然后它将使用公共行作为上下文以对齐更改:

It will then use common lines as context to align the changes:

version 1           version  2
-------------       -------------
+before
 original line       original line
                    +after

此时,合并很容易解决,而不会与以下内容冲突:

At which point, the merge is easy to resolve without a conflict to the following:

before
original line
after

请注意,这样的合并仍可能导致冲突,因为Git可能没有足够的通用内容来正确对齐更改.特别是对于很小的文件,可能会发生这种情况.

Note that such a merge may still result in a conflict because Git might not have enough common content to align the changes properly. Especially for very small files this might happen.

这篇关于git中的3-Way合并-比较工作原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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