使用三向diff进行比较 [英] Use three way diff for diff

查看:94
本文介绍了使用三向diff进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

另一个S.O.问题显示了如何配置git以使用三向差异来解决合并冲突.

Another S.O. question shows how to configure git to use a three way diff for merge conflicts.

是否可以将这三种方式设置为标准diff操作的默认方式?如果我请求在具有公共根目录的版本之间进行区分(而不仅仅是其中一个版本),则从公共根目录进行的更改将显示在差异中.

Is it possible to set up this three way style as the default for a standard diff operation? If I request a diff between versions where there is a common root (that isn't just one of the versions), changes from the common root will be shown in the diff.

推荐答案

恐怕答案是否定的.

为此,不管您在调用git diff时如何指定参数,它总是只考虑两个实体(blob或tree(大多数时间是从引用它们的提交推断出的)). 换句话说,这是设计使然:git diff考虑单独的对象,并且不进行任何历史遍历. 要引用git diff手册页:

The ratonale for this is that no matter how you specify the arguments when calling git diff, it always considers just two entities (blobs or trees (most of the time inferred from the commits referring to them)). In other words, that's by design: git diff considers separate objects and does not do any history traversal. To cite the git diff manual page:

有关拼写<commit>的方法的完整列表,请参见指定修订版本" gitrevisions(7)中的部分.但是,"diff"是关于比较两个端点 范围,以及范围符号("<commit>..<commit>"和 "<commit>...<commit>")不表示指定范围"中定义的范围 gitrevisions(7)中的部分.

For a more complete list of ways to spell <commit>, see "SPECIFYING REVISIONS" section in gitrevisions(7). However, "diff" is about comparing two endpoints, not ranges, and the range notations ("<commit>..<commit>" and "<commit>...<commit>") do not mean a range as defined in the "SPECIFYING RANGES" section in gitrevisions(7).

另一方面,有了合适的外壳,您应该可以自己完成该操作.假设有两个提交rev1rev2,您可以使用

On the other hand, with a suitable shell, you should be able to do that thing yourself. Say, given two commits, rev1 and rev2, you could use

git-diff3() {
  local rev1="$1" rev2="$2"
  diff3 <(git show "$rev1") \
        <(git show $(git merge-base "$rev1" "$rev2")) \
        <(git show "$rev2")
}

在可以理解<(...)(例如bash)的外壳中.

in a shell which understands <(...) (e.g. bash).

此功能需要按摩以使其更有用/更不易损坏,但我希望您能理解.

This function requires massaging to make it more useful/less fragile but I hope you get the idea.

这篇关于使用三向diff进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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