What are the differences between the following git commands?
git diff HEAD
git diff HEAD^
git diff --cached
or the synonymgit diff --staged
git diff
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
HEAD
is the current HEAD
pointer in the tree, HEAD^
is the commit before HEAD
. --cached
I'm not sure about.--cached
will show you any changes you have made but haven't added to the index.
The git tutorial on kernal.org is a very good read.
git add
but not yet committed.git add
.It looks like this:
Working Directory <----+--------+-------+
| | | |
| diff HEAD | |
V | | |
"git add" | | |
| | | diff
| | | |
V | | |
Index <----+-----|--------|-------+
| | | |
| diff --staged | |
V | | |
"git commit" | | |
| | | |
| | | |
V | | |
HEAD <----+-----+ |
| |
| diff HEAD^
V |
previous "git commit" |
| |
| |
V |
HEAD^ <-------------+
From the Git Community Book:
git diff
will show you changes in the working directory that are not yet staged for the next commit.
git diff --cached
will show you the difference between the index and your last commit; what you would be committing if you run "git commit" without the "-a" option.
git diff HEAD
shows changes in the working directory since your last commit; what you would be committing if you run "git commit -a".