1

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:

enter image description here

Then, a range-diff:

enter image description here

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?

Robin Dos Anjos
  • 309
  • 2
  • 11
  • As a developer who has worked on an 80 billion dollar product, McKessons Connect application (medical), I will say IntelliJ was a friend, it’s diff tool is my personal favorite. [GitHub’s desktop](https://desktop.github.com/) application also makes diff’s pretty easy. I wouldn’t use this tool above in my work as I don’t find it intuitive. – Richard Tyler Miles Dec 20 '21 at 01:04
  • There is a tool called [*interdiff*](https://linux.die.net/man/1/interdiff) that you might like. I've never been that fond of it myself. – torek Dec 20 '21 at 02:54
  • Indeed interdiff is very good alternative although it doesn't produce the same output as a range-diff. Thank you @torek! – Robin Dos Anjos Dec 20 '21 at 16:11

0 Answers0