I wonder why git tells me this:?
$ git diff MyFile.txt
diff --git a/MyFile.txt b/MyFile.txt
index d41a4f3..15dcfa2 100644
Binary files a/MyFile.txt and b/MyFile.txt differ
Aren't they text files?
I have checked the .gitattributes and it is empty. Why I am getting this message? I cannot get diffs as I use to anymore
ADDED:
I've noticed there is an @
in the file permissions, what is this? Could this be the reason?
$ls -all
drwxr-xr-x 5 nacho4d staff 170 28 Jul 17:07 .
drwxr-xr-x 16 nacho4d staff 544 28 Jul 16:39 ..
-rw-r--r--@ 1 nacho4d staff 6148 28 Jul 16:15 .DS_Store
-rw-r--r--@ 1 nacho4d staff 746 28 Jul 17:07 MyFile.txt
-rw-r--r-- 1 nacho4d staff 22538 5 Apr 16:18 OtherFile.txt
I have had same problem. I found the thread when I search solution on google, still I don't find any clue. But I think I found the reason after studying, the below example will explain clearly my clue.
for now, the file new.txt is considered as a text file.
you will get this result
and try this
you will get below
Change the Aux.js to another name, like Sig.js.
The source tree still shows it as a binary file, but you can stage(add) it and commit.
It simply means that when git inspects the actual content of the file (it doesn't know that any given extension is not a binary file - you can use the attributes file if you want to tell it explicitly - see the man pages).
Having inspected the file's contents it has seen stuff that isn't in basic ascii characters. Being UTF16 I expect that it will have 'funny' characters so it thinks it's binary.
There are ways of telling git if you have internationalisation (i18n) or extended character formats for the file. I'm not sufficiently up on the exact method for setting that - you may need to RT[Full]M ;-)
Edit: a quick search of SO found can-i-make-git-recognize-a-utf-16-file-as-text which should give you a few clues.
I had this same problem after editing one of my files in a new editor. Turns out the new editor used a different encoding (Unicode) than my old editor (UTF-8). So I simply told my new editor to save my files with UTF-8 and then git showed my changes properly again and didn't see it as a binary file.
I think the problem was simply that git doesn't know how to compare files of different encoding types. So the encoding type that you use really doesn't matter, as long as it remains consistent.
I didn't test it, but I'm sure if I would have just committed my file with the new Unicode encoding, the next time I made changes to that file it would have shown the changes properly and not detected it as binary, since then it would have been comparing two Unicode encoded files, and not a UTF-8 file to a Unicode file.
You can use an app like Notepad++ to easily see and change the encoding type of a text file; Open the file in Notepad++ and use the Encoding menu in the toolbar.
We had this case where an .html file was seen as binary whenever we tried to make changes in it. Very uncool to not see diffs. To be honest, I didn't checked all the solutions here but what worked for us was the following:
git deletion
. Git saysDeleted file with mode 100644 (Regular) Binary file differs
New file with mode 100644 (Regular) 1 chunk, 135 insertions, 0 deletions
The file is now added as a regular text fileFrom now on, any changes I made in the file is seen as a regular text diff. You could also squash these commits (1, 2, and 3 being the actual change you make) but I prefer to be able to see in the future what I did. Squashing 1 & 2 will show a binary change.
If
git check-attr --all -- src/my_file.txt
indicates that your file is flagged as binary, and you haven't set it as binary in.gitattributes
, check for it in/.git/info/attributes
.