Why does git diff not show any difference after git add command? [duplicate]
It should just be:
git diff --cached
--cached
means show the changes in the cache/index (i.e. staged changes) against the current HEAD
. --staged
is a synonym for --cached
.
--staged
and --cached
does not point to HEAD
, just difference with respect to HEAD
. If you cherry pick what to commit using git add --patch
(or git add -p
), --staged
will return what is staged.
A simple graphic makes this clearer:
git diff
Shows the changes between the working directory and the index. This shows what has been changed, but is not staged for a commit.
git diff --cached
Shows the changes between the index and the HEAD (which is the last commit on this branch). This shows what has been added to the index and staged for a commit.
git diff HEAD
Shows all the changes between the working directory and HEAD (which includes changes in the index). This shows all the changes since the last commit, whether or not they have been staged for commit or not.
Also:
There is a bit more detail on 365Git.