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:

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:

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

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:

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

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.