What is the difference between git diff HEAD
and git diff --staged
? I tried both but both give the same output.
Suppose this output for git status
:
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# new file: y
#
# Changes not staged for commit:
# (use "git add ..." to update what will be committed)
# (use "git checkout -- ..." to discard changes in working directory)
#
# modified: x
#
As you see, there is one file modified but not staged for commit, and a new file added that is ready to be committed.
git diff --staged
will only show changes to files in the "staged" area.
git diff HEAD
will show all changes to tracked files. If you have all changes staged for commit, then both commands will output the same.