I staged a few changes to be committed. How do I see the diffs of all files which are staged for the next commit? Is there a handy one-liner for this?
git status only shows names of files which are staged, but I want to see the actual diffs.
git-diff(1) man page says:
git diff [–options] [–] […]
This form is to view the changes you made relative to the index (staging area for the next commit). In other words, the differences are what you could tell git to further add to the index but you still haven’t. You can stage these changes by using git-add(1).
It should just be:
git diff --cached
--cached means show the changes in the cache/index (i.e. staged changes) against the current
--staged is a synonym for
--cached does not point to
HEAD, just difference with respect to
HEAD. If you cherry pick what to commit using
git add --patch (or
git add -p),
--staged will return what is staged.
A simple graphic makes this clearer:
Shows the changes between the working directory and the index. This shows what has been changed, but is not staged for a commit.
git diff –cached
Shows the changes between the index and the HEAD (which is the last commit on this branch). This shows what has been added to the index and staged for a commit.
git diff HEAD
Shows all the changes between the working directory and HEAD (which includes changes in the index). This shows all the changes since the last commit, whether or not they have been staged for commit or not.
There is a bit more detail on 365Git.
git status -v also shows the staged changes!
(meaning you need to have staged —
git add — some changes. No staged changes, no diff with
git status -v.
It does that since Git 1.2.0, February 2006)
In its long form (default),
git status has an undocumented “verbose” option which actually display the diff between HEAD and index.
And it is about to become even more complete: see “Show both staged & working tree in git diff?” (git 2.3.4+, Q2 2015):
git status -v -v