gitdiffgit-mergeaggregation

Git diff on topic branch, excluding merge commits that happened in the meantime?


Let's say I have the following situation:

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

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.

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.

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.

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).


Solution

  • 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