While working with Git it is often required to check the changes between different areas.
Probably everyone knows the git diff
, that shows the changes between the Working Directory and the Staging Area (git diff
unstaged).
But it is also often needed to shows the changes between the Staging Area and the HEAD
(git diff
staged) or between the Working Directory and the HEAD
(git diff
staged and unstaged).
Cool Tip: Did something wrong? Want to undo everything? You can easily revert all changes back to the last commit! Read more →
Git – Diff Staged and Unstaged Files
First of all it is required to clearly understand the meaning of the following terms:
Staging Area (aka. cache, index) – is a temporary area where you add files with git add
command.
HEAD
– is a reference to a specific commit (normally to the the last commit in a local repository).
Git Diff Unstaged
Shows the changes between the Working Directory and the Staging Area:
$ git diff
Git Diff Staged
Shows the changes between the Staging Area and the HEAD
:
$ git diff --staged - or - $ git diff --cached - or - $ git status -v
Create an alias git diffs
, if you need to check these changed often:
$ git config --global alias.diffs 'diff --staged'
Git Diff Staged and Unstaged
Shows all the changes between the Working Directory and the HEAD
:
$ git diff HEAD - or - $ git status -vv
Create an alias git diffh
, if you need to check these changed often:
$ git config --global alias.diffh 'diff HEAD'
+1, useful
+1, useful
Thanks – useful!