How to fix diff: Binary files ... and ... differ

Problem:

You want to compare two text files using diff, but you only see this error message:

Binary files a.txt and b.txt differ

Solution

This often occurs if there are just a few binary characters in a file, even though it is actually a text file. Force comparing in text mode by using the --text flag:

diff --text a.txt b.txt