'git status' shows changed files, but 'git diff' doesn't

I've had a look at all similar questions. However, I've double checked and something strange is definitely happening.

On one server (Solaris with Git 1.8.1) I cloned the Git repository then copied the .git folder into my existing live files. This worked perfectly, I could run

git status

then

git diff [filename]

to check any files that were different.

On another server (Solaris with Git 1.7.6) I'm doing exactly the same however

git diff [filename]

shows nothing, even if the contents of the file is definitely different. I have also tested adding a new file, committing it, and then editing. The same issue, git status shows the file as changed, but git diff shows nothing. If I download the changed file and run a diff locally then I get diff output.


Solution 1:

I added the file to the index:

git add file_name

And then ran:

git diff --cached file_name

You can see the description of git diff here.

If you need to undo your git add, then please see here: How do I undo 'git add' before commit?

Solution 2:

For me, it had something to do with file permissions. Someone with Mac/Linux on my project seems to commit some files with non-default permissions which my Windows Git client failed to reproduce.

The solution for me was to tell Git to ignore file permissions:

git config core.fileMode false

Other insight: How do I make Git ignore file mode (chmod) changes?

Solution 3:

There are a few reasons why git status might show a difference but git diff might not.

  • The mode (permission bits) of the file changed-- for example, from 777 to 700.

  • The line feed style changed from CRLF (DOS) to LF (UNIX)

The easiest way to find out what happened is to run git format-patch HEAD^ and see what the generated patch says.

Solution 4:

I had an issue where hundreds of line endings were modified by some program and git diff listed all source files as changed. After fixing the line endings, git status still listed the files as modified.

I was able to fix this problem by adding all files to the index and then resetting the index.

git add -A
git reset

core.filemode was set to false.