Mercurial:如何才能只看到合并引入的更改?
我正在努力养成进行代码审查的习惯,但合并使这个过程变得困难,因为我不知道如何要求 Mercurial“仅显示合并引入的更改,这些更改在其父级中都不存在”。
或者,稍微正式一点(感谢 Steve Losh):
显示合并中在其父项中不存在的每个块,并显示在其父项中存在但在 3 中也不存在的每个块。
例如,假设我有一个包含两个文件的存储库, a和b。如果“a”在修订版 1 中更改,“b”在修订版 2 中更改(位于单独的分支上),并且这两个更改在修订版 3 中合并,我将得到如下所示的历史记录
@ 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
:
$ 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 没有引入新的更改(或者,如果合并期间出现冲突,我想仅查看该冲突的解决方案)。比如:
$ hg di -c 3 $
那么,我该怎么做呢?
ps:我知道我可以使用rebase
减少存储库中的合并数量...但这不是我的问题 - 我的问题是弄清楚合并更改了哪些内容。
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.
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
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
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 $
So, how can I do this?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短的回答是:您无法使用任何现有的 Mercurial 命令来执行此操作。
运行
hg diff -c 3
将显示3
与其第一个父级之间的更改 - 即运行hg merge
时所在的变更集>。当您将分支视为不仅仅是简单的变更集时,这是有道理的。当您运行
hg up 1 && hg merge 2
您告诉 Mercurial:“将变更集2
合并到变更集1
”。如果您使用命名分支,那就更明显了。假设您的示例中的变更集
2
位于名为rewrite-ui
的命名分支上。当您运行hg update 1 && hg merge rewrite-ui
您实际上是在说:“将rewrite-ui
分支中的所有更改合并到当前分支中。”当您稍后在此变更集上运行hg diff -c
时,它会向您显示引入到default
分支(或发生的任何分支1
)的所有内容通过合并),这是有道理的。不过,从你的问题来看,你似乎正在寻找一种表达方式:
这不是一件简单的事情来计算(我什至不确定我刚才是否得到了描述)。不过,我绝对可以看到它有什么用,所以如果你能明确地定义它,你可能会说服我们其中一位阅读过 SO 的 Mercurial 贡献者来实现它。
The short answer: you can't do this with any stock Mercurial command.
Running
hg diff -c 3
will show you the changes between3
and its first parent -- i.e. the changeset you were at when you ranhg merge
.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 changeset2
into changeset1
".It's more obvious if you're using named branches. Say changeset
2
in your example was on a named branch calledrewrite-ui
. When you runhg update 1 && hg merge rewrite-ui
you're effectively saying: "Merge all the changes in therewrite-ui
branch into the current branch." When you later runhg diff -c
on this changeset it's showing you everything that was introduced to thedefault
branch (or whatever branch1
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:
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.
为了进行代码审查,您确实只想查看正在审查的项目中的更改。为此,我们为每个故事使用一个新分支,并使用拉取请求来突出更改,在创建拉取请求之前将所有更改合并到故事分支中。我们在 bitbucket 上托管我们的代码,审查/拉取请求工具真的非常好,提供并排差异。
使用 side-by- 拉取请求侧面差异
In order to do code reviews you really want to see just the changes in the project that you are reviewing. To that end we use a new branch for each story and use pull requests to spotlight the changes, having merged all changes into the story branch before creating the pull request. We host our code on bitbucket and the review / pull request tools are really very good, offering a side by side diff.
Pull requests with side-by-side diffs