Super Charged Git Diffs with Difftastic

Super Charged Git Diffs with Difftastic

I actually enjoy using git for my code reviews to read what has changed, rather than using the Github UI and it's all because of a fantastic tool called Difftastic. git's default diff output is ugly to say the least. It's made to be human readable, but really it's meant for making patches for git to ingest with git apply. If you haven't seen it before it looks something like this:

difftastic on  main [!] is 📦 v0.1.0 via 🦀 v1.75.0 ❯ git diff diff --git a/src/main.rs b/src/main.rs index 576cb98..7cf6b10 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -fn db_query(db: DbConnection, query: String) -> Result<Queried, Error> { +fn db_query(db: DbConnection, query: impl Into<String>) -> Result<Queried, Error> {      // Code      // goes      // here

It shows you what file has changed, between what commits, it's file perms, the lines that changed, and then the changes themselves with lines that have changed. It's very much meant to be parsed by a computer and coincidentally be read by a human.

The problem with this is that git is not aware of the programming language being changed here. It just knows, via a line diffing algorithm, that a change happened on the line, not how in any meaningful way.

We as programmers could, with a bit of looking see that the input type for the query parameter changed to impl Into<String>. However, we work with structured text all day! The change has meaning, it is not the whole line that changed, it is the type alone that changed.

For years I would use diff-so-fancy or later Delta to make these diffs more readable, but even though they were better at highlighting the changes between lines, they mainly showed me the lines that changed like git would by default with some extra highlighting on a spot to show the change in a line. Once I saw Difftastic it blew by mind. Let's take a look at the example above again with Difftastic:

difftastic on  main [!] is 📦 v0.1.0 via 🦀 v1.75.0 ❯ git diff src/main.rs --- Rust 1 fn db_query(db: DbConnection, query: impl Into<String>) -> Result<Queried, Error> { 2     // Code 3     // goes 4     // here  It's worth noting since I can't put color in alt text that only `impl Into<` and the closing `>` bracket were turned green

It's the same exact diff, but so much easier to read and less cognitive overhead playing spot the difference. The text impl Into<> was added on the line and nothing else was changed. This alone has made reading changes so much easier. The fact that it's language aware means that I can see the information I care about so much easier.

I can't recommend it enough for every day usage to find what changed in your piles of YAML you chuck into the cloud, your code, or just about any text file you'd want to commit. If you want more examples you should check out it's website, because this is only a taste of what it can do.