When rebasing a git branch, especially after conflicts resolution, I like comparing the two patches, i.e. the diff between the main branch and my branch before rebasing and the diff between the main branch and my branch after rebasing. The reason why I do this is to make sure I resolved the conflicts properly and did not introduce bugs as a result of that.
Fortunately, git 2.19 introduced the wonderful git range-diff. And most of the time, it does exactly what I expect. It takes all the commits, before and after the rebase, match them one by one and show what's different. Reallly neat.
Sometimes, however, the conflicts resolution is such a pain and the number of commits to rebase is so high that I simply decide to squash them and resolve all the conflicts at once. And now I have a problem. Before updating the branch, I had N commits, but after that, I only have a single commit left which the result of squashing the N commits on top of the main branch. So range-diff cannot help me anymore. Even if the two patches are very similar, the number of commits differ so they cannot be matched one by one.
An alternative could be to dump the two diffs into two files and then compare those. While that would definitely work, the result would not be very readable. Here's a quick comparison. First, a diff of diffs:
Then, a range-diff:
I think we can easily agree that the latter is far easier to read. Another approach could be to squash the commits before conflicts resolution as well. This way I only have a single commit on both sides and range-diff can be used again. That would work too, but I'm a lazy guy. I don't want to run extra git commands and produce garbage commits for one-time use. Also, I could get it wrong. And that would be a shame since I do this to double-check that I did things properly in the first place.
So my question is the following: Is there another alternative? I want to be able to produce a diff of two arbitrary patches that don't necessarily have the same number of commits. But I also like the way range-diff formats the diff into something very easy to read. Is there another way to make it work? Is there any third-party tools which achieve similar results?


I know it's been a while. I'm now using a home-made solution but never took the time to share it here. Sorry for procrastinating!
I basically wrote a NodeJS script which performs the diffing of diffs manually by running multiple git commands successively. Then the output is colorized in such a way that, in combination with
less -R, it will be shown exactly like agit range-diff.The script has a few side effects as it will write two files on disk to run the diff against them and then delete them. It should be fine for most users but I think it's still worth mentioning.
You can then use it in the following way:
This will first compute the following two diffs and write them on disk:
Then it computes the diff of diffs and colorizes it:
This is incredibly handy, especially if I've squashed and rebased a
topicbranch. It lets me compare the changes across N commits against the changes made in a single commit post-rebase:In the example above, I squashed ten commits into one and then rebased it. And I'm still able to compare the two histories.
You can pipe the output into
lessto enjoy the nice colors:I think this should be a built-in feature of git. I use it very very often.
Here's the code: