Override git's choice of binary file to text

The way files are actually stored inside the Git repository is not relevant to how they are treated when displayed. So the git diff program, when asked to compare two files, first obtains both complete files from the repository and then runs a difference algorithm against them.

Normally, git diff looks for non-printable characters in the files and if it looks like the file is likely to be a binary file, it refuses to show the difference. The rationale for that is binary file diffs are not likely to be human readable and will probably mess up your terminal if displayed.

However, you can instruct git diff to always treat files as text using the --text option. You can specify this for one diff command:

git diff --text HEAD HEAD^ file.txt

You can make Git always use this option by setting up a .gitattributes file that contains:

file.txt diff

The diff attribute here means:

A path to which the diff attribute is set is treated as text, even when they contain byte values that normally never appear in text files, such as NUL.


Look at Git Attributes -- they may be able to help you by specifying that a certain file extension is to be treated as text.


If you are trying to compare or merge text files and git is saying they are binary files, they may just have different encoding (e.g. UTF-8 and ANSI). See the answer I gave on this post.

Tags:

Text

Binary

Git