Skip to content
Tech News
← Back to articles

How to build a `Git diff` driver

read original get Git Diff Custom Tool → more articles
Why This Matters

This article highlights the importance of customizing Git diff workflows by creating external diff drivers, which can enhance the comparison of complex or binary files like OpenAPI specs. Such customization improves developer productivity and accuracy in code reviews, especially for specialized file formats. It also sheds light on the technical details necessary to implement these drivers effectively, filling a gap in existing documentation.

Key Takeaways

Something I've been meaning to write about since November 2024 is how to create an external command for diffing between files with git diff .

I found that while I was implementing renovate-packagedata-diff that there seemed to be a lack of documentation around how to do it, so it would be worthwhile me blogging about it.

(I've since found that there is some documentation in the Git Diffs man page, but it wasn't exactly well discoverable)

It's been at the back of my mind as a TODO for some time, and then I was nudged about it fairly recently by Andrew Nesbitt's good post on Git Diff Drivers, and this week looking at diffing OpenAPI specs with oasdiff .

I thought I'd use this as an opportunity for blogging about how this works, as well as adding a separate for oasdiff as a diff driver.

Note that this is a case where we want to expose more information in our output, and can't rely on the textconv method to convert a (binary) file to a more diff-able textual format.

In a lot of cases, using textconv is likely sufficient!

What arguments do we need to handle?

Although many tools would work out-of-the-box if they expect to be run as tool [before] [after] , git diff passes 7 arguments to the external tool it's calling.

Although surprising, this does provide some richer data that is useful to have.

... continue reading