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 clon
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 to undo 'git add' before commit?
I stumbled upon this problem again. But this time it occurred for a different reason. I had copied files into the repo to overwrite the previous versions. Now I can see the files are modified but diff doesn't return the diffs.
For example, I have a mainpage.xaml file.
In File Explorer I pasted a new mainpage.xaml file over the one in my current repo.
I did the work on another machine and just pasted the file here.
The file shows modified, but when I run git diff, it will not show the changes. It's probably because the fileinfo on the file has changed and git knows that it isn't really the same file. Interesting.
You can see that when I run diff on the file it shows nothing, just returns the prompt.
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.
I've just run in a similar issue. git diff file
showed nothing because I added file to the Git index with some part of its name in uppercase: GeoJSONContainer.js
.
Afterwards, I've renamed it to GeoJsonContainer.js
and changes stopped being tracked. git diff GeoJsonContainer.js
was showing nothing. I had to remove the file from the index with a force flag, and add the file again:
git rm -f GeoJSONContainer.js
git add GeoJSONContainer.js
I had a similar problem: git diff
would show differences, but git diff <filename>
would not. It turned out that I set LESS
to a string including -F
(--quit-if-one-screen
). Removing that flag solved the problem.
I ran into this problem. My case was similar to the LESS issue posted by rcwxok.
In my case, I set the PAGER
environment variable to PAGER='less -RSF'
.
However, unlike the previous answers, I didn't want to remove the -F
option, because I explicitly put it there hoping to prevent showing the diff in less
if it's shorter than a screenful.
To get the desired result, instead of removing -F
, I added -X
: PAGER='less -RSFX'
. This both solved the git diff
issue and in addition it prevents showing short diffs with less
.