What are the differences between the following git commands?
git diff HEAD
git diff HEAD^
git diff --cached
or the synonym git diff --staged
git diff
git diff HEAD
- Shows what has changed since the last commit.git diff HEAD^
- Shows what has changed since the commit before the latest commit.git diff --cached
- Show what has been added to the index via git add
but not yet committed.git diff
- Show what has changed but hasn't been added to the index yet via git add
.It looks like this:
Working
Directory <----+--------+------+
| | | |
| | | |
V | | |
"git add" | | |
| diff | |
| | | |
V | | |
Index <----+ diff HEAD |
| | | |
| | | |
V | | |
"git commit" | | |
| diff --cached | |
| diff --staged | |
V | | |
HEAD <----+--------+ |
| |
| diff HEAD^
V |
previous "git commit" |
| |
| |
V |
HEAD^ <--------------------+