Mercurial:如何仅查看合并引入的更改? [英] Mercurial: how can I see only the changes introduced by a merge?

查看:118
本文介绍了Mercurial:如何仅查看合并引入的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图养成进行代码审查的习惯,但是合并使该过程变得困难,因为我不知道如何要求Mercurial仅显示合并中引入的更改,而这两项都不存在的父母."

I'm trying to get in the habit of doing code reviews, but merges have been making the process difficult because I don't know how to ask Mercurial to "show only changes introduced by the merge which were not present in either of its parents."

或者,更正式一点(感谢史蒂夫·洛什):

Or, slightly more formally (thanks to Steve Losh):

告诉我合并中每个父母都不存在的所有大块,并显示合并中三个父母中不存在的每个大块.

Show me every hunk in the merge that wasn't present in either of its parents, and show me every hunk present in either of its parents that isn't also present in 3.

例如,假设我有一个包含两个文件a和b的存储库.如果在版本1中更改了"a",则在版本2中更改了"b"(位于单独的分支上),并且在版本3中合并了这两个更改,因此我得到的历史记录如下:

For example, assume I have a repository with two files, a and b. If "a" is changed in revision 1, "b" is changed in revision 2 (which is on a separate branch) and these two changes are merged in revision 3, I'll get a history which looks like this:

    @    changeset:   3
    |\   summary:     Merged.
    | |
    | o  changeset:   2
    | |  summary:     Changing b
    | |
    o |  changeset:   1
    |/   summary:     Changing a
    |
    o  changeset:   0
       summary:     Adding a and b

但是,如果我要求查看修订版3 hg di -c 3引入的更改,Mercurial将向我显示与要求查看修订版1 hg di -c 1引入的更改相同的内容:

But if I ask to see the changes introduced by revision 3, hg di -c 3, Mercurial will show me the same thing as if I asked to see the changes introduced in revision 1, hg di -c 1:

    $ hg di -c 3
    --- a/a     
    +++ b/a     
    @@ -1,1 +1,1 @@ 
    -a 
    +Change to a
    $ hg di -c 1
    --- a/a     
    +++ b/a     
    @@ -1,1 +1,1 @@ 
    -a 
    +Change to a

但是,显然,这不是很有帮助-而是,我想告诉大家修订版3没有引入新的更改(或者,如果合并期间发生冲突,我只希望看到解决该冲突).像这样:

But, obviously, this isn't very helpful - instead, I would like to be told that no new changes were introduced by revision 3 (or, if there was a conflict during the merge, I would like to see only the resolution to that conflict). Something like:

    $ hg di -c 3
    $

那么,我该怎么做?

ps :我知道我可以使用rebase减少存储库中的合并数量……但这不是我的问题-我的问题是弄清楚合并中发生了什么更改.

ps: I know that I can reduce the number of merges in my repository using rebase… But that's not my problem - my problem is figuring out what was changed with a merge.

推荐答案

简短的答案:使用任何常规Mercurial命令都无法做到这一点.

The short answer: you can't do this with any stock Mercurial command.

正在运行hg diff -c 3将会向您显示3及其第一个父级之间的更改-即,您在运行hg merge时所处的更改集.

Running hg diff -c 3 will show you the changes between 3 and its first parent -- i.e. the changeset you were at when you ran hg merge.

当您将分支视为不仅仅是简单的变更集时,这很有意义.运行hg up 1 && hg merge 2时,您会告诉Mercurial:将更改集2合并到更改集1中".

This makes sense when you think of branches as more than just simple changesets. When you run hg up 1 && hg merge 2 you're telling Mercurial: "Merge changeset 2 into changeset 1".

如果您使用命名分支,则更明显.假设您的示例中的变更集2在名为rewrite-ui的命名分支上.当您运行hg update 1 && hg merge rewrite-ui时,您实际上是在说:将rewrite-ui分支中的所有更改合并到当前分支中."稍后当您在此变更集上运行hg diff -c时,它会向您显示通过合并引入到default分支(或任何分支1恰好处于打开状态)的所有内容.

It's more obvious if you're using named branches. Say changeset 2 in your example was on a named branch called rewrite-ui. When you run hg update 1 && hg merge rewrite-ui you're effectively saying: "Merge all the changes in the rewrite-ui branch into the current branch." When you later run hg diff -c on this changeset it's showing you everything that was introduced to the default branch (or whatever branch 1 happens to be on) by the merge, which makes sense.

不过,从您的问题来看,您似乎正在寻找一种表达方式:

From your question, though, it looks like you're looking for a way to say:

请向我显示此变更集中任何一个没有出现在其父母中的大块,并向我显示每个其父母中没有出现在3中的所有大块.

这不是一件容易的事情(我什至不确定我现在是否已经得到了描述).不过,我绝对可以看到它的用处,因此,如果您可以明确定义它,则可以说服我们其中一位阅读SO的Mercurial贡献者来实现它.

This isn't a simple thing to calculate (I'm not even sure I got the description right just now). I can definitely see how it would be useful, though, so if you can define it unambiguously you might convince one of us Mercurial contributors that read SO to implement it.

这篇关于Mercurial:如何仅查看合并引入的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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