Sam Holman - coder, gamer, geek.

Diffing After Git Rebase Conflict Resolution

UPDATE 31/07/14: Using comm with the -3 option to suppress lines common to both diffs seems to result in an even cleaner output. :-)

comm -3 <(git diff -w -U1 release...@{1}) <(git diff -w -U1 release)

ORIGINAL 17/07/14: I had a feature branch - branched from master, but wanted to rebase onto a different branch, release. There were conflicts during the rebase, and once resolved, I wanted to view a diff of my feature branch before and after the rebase to check the changes from conflict resolution, but without seeing the unrelated changes between master and release, as these weren't of concern.

I ended up doing this:

diff -U1 <(git diff -w -U1 release...@{1}) <(git diff -w -U1 release)

This basically diffs the result of a diff between the feature branch prior to the rebase and the common "merge base" between it and release with the diff of the feature branch post-rebase and the tip of the release branch.

The ... finds the latest common ancestor between the two pointers (as opposed to the default git diff behaviour, which looks at the tip of the two), and the @{1} refers to the commit ref prior to the latest repoint of HEAD. If this isn't correct you can use git reflog to find your latest pre-rebase commit.

If you're unfamiliar with diff in general, the -U1 makes diff show us only one line of context (to make it easier to spot the actual lines we're interested in), and the -w omits whitespace-only changes.

It isn't pretty, but achieved pretty much the desired result. Anyone have any cleaner methods of doing this? Tweet me please!

« Back