0

Situation:

I have Git 1.9.5.github.0 installed on Windows 7. I currently have a version of a file in each or three areas (repository, staging index, and working directory). All three versions of the file are different in that each has more lines of text than the older.

Problem:

When I type in the commands git diff, git diff --cached first_file.txt, or git diff HEAD; the response displays that it detects differences but it doesn't show these differences. ----(see code below)

Z:\myFirstGit [master +0 ~1 -0]> git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   first_file.txt

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   first_file.txt

Z:\myFirstGit [master +0 ~1 -0 | +0 ~1 -0]> git diff
diff --git a/first_file.txt b/first_file.txt
index 2b6f7c0..0090cbf 100644
Binary files a/first_file.txt and b/first_file.txt differ
Z:\myFirstGit [master +0 ~1 -0 | +0 ~1 -0]> git diff head
diff --git a/first_file.txt b/first_file.txt
index e1a914a..0090cbf 100644
Binary files a/first_file.txt and b/first_file.txt differ
Z:\myFirstGit [master +0 ~1 -0 | +0 ~1 -0]> git diff --cached first_file.txt
diff --git a/first_file.txt b/first_file.txt
index e1a914a..2b6f7c0 100644
Binary files a/first_file.txt and b/first_file.txt differ

I was expecting something like:

 > git diff
diff --git a/first_file.txt b/first_file.txt
index e1a914a..0090cbf 100644
--- a/first_file.txt
+++ b/first_file.txt
@@ -1 +1,2 @@
 This is the first_file test.
+One more line.

Question:

Why am I getting the response "Binary files a/first_file.txt b/first_file.txt differ" and not an explicit display of the differnces?

Kram_Koorbse
  • 442
  • 5
  • 19

3 Answers3

1

Your file certainly contains data which makes Git treating the file as binary. Thus it cannot show the differences.

You can force Git to consider your file as text for the diff operation by writing:

first_file.txt diff

in the .gitattributes file. See this similar question and the doc of .gitattribute.

Community
  • 1
  • 1
Frodon
  • 3,684
  • 1
  • 16
  • 33
0

This usually occurs when the mode of the files change.

You can see the diff actually in this bit:

100644
--- a/first_file.txt
+++ b/first_file.txt

This means that the mode of the file has changed to 644. (See file modes)

ddavison
  • 28,221
  • 15
  • 85
  • 110
0

First I would like to thank Frodon for providing the link that lead me to a solution to my issue.

Solution

The issue was in the encoding of the file. I initially did all or my text file edits in Notepad. From the link provided by Frodon, I found a post where the person used Notepadd++ to find out what encoding was being used and to change it.

  1. After reading this, I opened my first_file.txt in Notepad++
  2. I selected the Encoding tab from the menubar and saw that the encoding was marked as 'Encode in UCS-2 Big Endian'.
  3. I changed the encoding to Encode in UTF-8 without BOM.
  4. I added 'Change encoding' as text to a new line inside first_file.txt. Saved it, then git add first_file.txt and lastly git commit first_file.txt -m 'Changed encoding'.
  5. Now when I make an edit to first_file.txt, the edits are displayed like they should with the differences shown after typing the command git diff
Kram_Koorbse
  • 442
  • 5
  • 19