Your file is already staged to be committed. You can show it's diff using the --cached option of git. To unstage it, just do what git status suggests in it's output ;) You can check The Git Index For more info.
The main difference between the commands is that git diff is specially aimed at comparisons, and it's very powerful at that: It can compare commits, branches, a single file across revisions or branches, etc. On the other hand, git status is specifically for the status of the working tree.
You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch.
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?
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?
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 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.
As already noted in a previous answer, this situation may arise due to line-ending problems (CR/LF vs. LF). I solved this problem (under Git version 2.22.0) with this command:
git add --renormalize .
According to the manual:
--renormalize
Apply the "clean" process freshly to all tracked files to
forcibly add them again to the index. This is useful after
changing core.autocrlf configuration or the text attribute in
order to correct files added with wrong CRLF/LF line endings.
This option implies -u.
I suspect there is something wrong either with your Git installation or your repository.
Try running:
GIT_TRACE=2 git <command>
See if you get anything useful. If that doesn't help, just use strace and see what's going wrong:
strace git <command>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With