在Mercurial中,如何查看合并变更集和一个父级之间的差异而没有另一个父级的变化? [英] In mercurial, how to see diff between in a merge changeset and one parent without changes from the other parent?

查看:71
本文介绍了在Mercurial中,如何查看合并变更集和一个父级之间的差异而没有另一个父级的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这个琐碎的回购:

mkdir temp
cd temp
hg init
echo abc > file1
hg ci -A -m init
echo def >> file1
echo hey > file2
hg ci -A -m A
hg up -r0
echo ghi >> file1
echo hey > file3
hg ci -A -m B
hg merge
hg ci -m merge

在合并过程中,取"ghi"(哪一边并不重要).

During merge, take "ghi" (doesn't really matter which side).

DAG为:

0 - 2 - 3
 \- 1 -/

hg diff -r1:3显示文件1的更改和新文件3.

hg diff -r1:3 shows file1 change and new file3.

hg diff -r2:3显示新的文件2. hg log -p -r3hg st --change 3相同,因为2是第一个父级.

hg diff -r2:3 shows new file2. Same for hg log -p -r3 and hg st --change 3, because 2 is the first parent.

我的问题是:我如何看到1到3之间的变化减去2的变化(在概念上是d(1:3) - d(0:2)?)?

My question is: how can I see the changes between 1 and 3 minus the changes in 2, which is conceptually d(1:3) - d(0:2)?

我希望只能看到file1的更改. hg log -r3 -v仅显示"files:file1"(我想是因为它是更改ctx中的唯一文件),但奇怪的是,hg log -r3 --debug也显示了"files +:file2".

I expect to see only file1 change. hg log -r3 -v only shows "files: file1" (I guess because it's the only file in the change ctx), but curiously, hg log -r3 --debug also shows "files+: file2".

如果我运行hg view(由捆绑的hgk扩展名提供)并单击r3,则它仅显示file1.我看不懂tcl/tk代码,但似乎诀窍在于contmergediff函数中,该函数在合并中获取文件列表,但在某种程度上忽略了file2.

If I run hg view (provided by the bundled hgk extension) and click on r3, it shows only file1. I can't read tcl/tk code, but it seems like the trick is in a contmergediff function where it gets the list of files in a merge, in which it somehow omits file2.

FWIW,TortoiseHg与上述所有操作均不同:单击r3在文件列表中显示"M file1"和"A file2",但在file1中未显示任何实际更改.单击其他父项",显示"M file1"和"A file3",与"diff -r1:3"相同.

FWIW, TortoiseHg is different from all of the above: clicking on r3 shows "M file1" and "A file2" in the file list, but shows no actual change in file1. Click "Other Parent" shows "M file1" and "A file3", which is the same as "diff -r1:3".

一个现实的用例是:r1是我的,而r2是同事的.先前,同事审查了r1(差异0:1),但他没有将其合并,而是要求审查r2.因此,我查看了r2(差异0:2),然后他进行了合并.然后,当我看到差异1:3时,我不得不忘记我曾经回顾过r2.如果合并差异很小,我可以使用hgk.但是,如果它很大,我真的需要在vdiff中看到它.

A real world use case is this: r1 is mine, and r2 is a colleague's. Earlier, the colleague reviewed r1 (diff 0:1), but he didn't merge it before asking for review of r2. So I reviewed r2 (diff 0:2), and later he did the merge. Then when I see diff 1:3, I have to forget about that I've ever reviewed r2. If the merge diff is small, I can just use hgk. But if it's big, I really need to see it in vdiff.

(更新),现在有一个 mergediff扩展.如果有人尝试并发现它可行,请添加答案.

(UPDATE) Now there's a mergediff extension. If someone tries and finds it work, please add an answer.

推荐答案

这是一个猜测(尽管我不确定它是否确实满足您的要求).命令

Here's a guess (though I'm not sure if it really does what you want). The command

$ hg log --template {files} -r <merge-revision>

列出通过合并更改的文件.此输出可用作 diff 命令的文件列表,以仅显示您感兴趣的更改.

lists the files, which have been changed by a merge. This output could be used as a list of files for the diff command, to show only the changes you're interested in.

在您的示例中,以下代码应显示合并对修订1中的您的贡献所做的工作:

Applied to your example, the following should show what the merge did with your contributions in revision 1:

$ hg diff -r 1:3 `hg log --template '{files}' -r 3`
diff --git a/file1 b/file1
--- a/file1
+++ b/file1
@@ -1,2 +1,2 @@
 abc
-def
+ghi

类似地,下面的命令应该向您展示合并如何影响版本2中您的同事的更改:

Similarly, the command below should show you how the merge affected your colleague's changes in revision 2:

$ hg diff -r 2:3 `hg log --template '{files}' -r 3`
# no output, since your colleague decided to keep her *ghi*

这篇关于在Mercurial中,如何查看合并变更集和一个父级之间的差异而没有另一个父级的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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