git-diff: Only show changes staged for committing

Alexey picture Alexey · Apr 26, 2012 · Viewed 8.6k times · Source

I want to see diff on files that I've added to commit (git add something). I can do this:

git diff HEAD `git status -s | grep ^M | cut -c 4-`

Is there a shorter way?

Answer

ThiefMaster picture ThiefMaster · Apr 26, 2012

You can use git diff --staged (or git diff --cached) to see the diff that will be used when committing.

From the manpage:

git diff [--options] --cached [<commit>] [--] [<path>...]
This form is to view the changes you staged for the next commit relative to the named <commit>. Typically you would want comparison with the latest commit, so if you do not give <commit>, it defaults to HEAD. If HEAD does not exist (e.g. unborned branches) and <commit> is not given, it shows all staged changes. --staged is a synonym of --cached.