主题分支上的Git diff,排除同时发生的合并提交? [英] Git diff on topic branch, excluding merge commits that happened in the meantime?

查看:270
本文介绍了主题分支上的Git diff,排除同时发生的合并提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下情况:

Let's say I have the following situation:

    B---D---F---G topic
   /       /
--A---C---E master

对于代码审查的目的,我想从提交A中提取差异提交G,但不包括发生在主分支上的提交E和C,也不包括提交F,这是合并提交。

For code review purposes, I would like to pull out a diff from commit A to commit G, but not including commits E and C which happened on the master branch, and also not including commit F which is a merge commit.

换句话说,我想生成一个包含从F到G的变化的差异,并将这些变化与从A到D的变化汇总在一起。

In other words, I would like to generate a diff that contains changes from F to G and aggregate those changes with changes from A to D.

换句话说,我希望review diff只包含来自主题分支的更改,不包括同时发生的大量代码。

In other-other words, I want the review diff to contain only my changes from the topic branch, not including a bunch of code from master that happened in the meantime.

这可能吗?如果git无法处理这种差异聚合,我会非常感激,如果有人能够提供一些关于如何外部命令可以做到这一点的指示(以便我可以尝试编写一个bash脚本,可以做到这一点)。 >

Is this possible? If git cannot handle such "diff aggregations", I would be very thankful if someone can provide some pointers as to how some external command can do that (so that I can try writing a bash script which would do the trick).

推荐答案

如果您不关心diff中context部分的内容,那么 git diff master。 .topic 会给你你想要的东西。在 C E 中引入的任何更改都被视为diff的基础的一部分,因此从 master 将在上下文中出现,但只有在主题分支中做出的实际更改将标记为 + - 作为更改。这通常是人们想要的代码评论。

If you don't care what's in the "context" part of the diffs, then git diff master..topic will give you what you want. Any changes introduced in C and E are considered part of the "base" of the diff, so the changes from master will be there in the context, but only the actual changes made in your topic branch will be marked with + or - as changes. That's usually what people want for code reviews.

如果您想要像从未发生过的合并一样行事,那么您必须重新整合它:

If instead you want to act like the merge never happened, you will have to rebase it out:

git rebase --onto A master

这篇关于主题分支上的Git diff,排除同时发生的合并提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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