Little Git Tricks: Enable Diff for Special Files

Git diff does its best to figure out if it can show you the differences in a file. However, sometimes this does not work - even when the file you are interested in is a text file. We use the UCS 2 character set for DbUp and Git believes that those are binary files. The resulting output is therefore rather useless:

We only see the message cannot show changes in a binary file

The .gitattributes file can be used to specify attributes per path. What sounds somewhat theoretical can be used to mark all *.sql files as diffable. All we need is to add this line to the .gitattributes file in our project:

*.sql diff

When we now try to watch any file ending with .sql we get the diff view back:

We now can see the line that changed

Should you end up in this situation, try that little entry in your .gitattributes file. It makes working with those files so much simpler.

Attention: This will only work when your diff-tool understands the character set of the file. If this isn't the case you end up with something like that:

We only get NUL tokens if the character set is wrong

This may still be more useful than the initial situation. If not, you simply remove the entry in the .gitattributes file.