I staged a few changes to be committed; how can I see the diff of all files which are staged for the next commit? I'm aware of git status, but I'd like to see the actual diffs - not just the names of files which are staged.
I saw that the 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).
Unfortunately, I can't quite make sense of this. There must be some handy one-liner which I could create an alias for, right?
From version 1.7 and later it should be:
Think about the
gitk
tool also , provided with git and very useful to see the changesgit gui
andgit-cola
are graphical utilities that let you view and manipulate the index. Both include simple visual diffs for staged files, andgit-cola
can also launch a more sophisticated side-by-side visual diff tool.See my closely related answer at How to remove a file from the index in git?, and also this official catalog of Git - GUI Clients.
You can use this command.
The
--cached
option ofgit diff
means to get staged files, and the--name-only
option means to get only names of the files.It should just be:
--cached
means show the changes in the cache/index (i.e. staged changes) against the currentHEAD
.--staged
is a synonym for--cached
.--staged
and--cached
does not point toHEAD
, just difference with respect toHEAD
. If you cherry pick what to commit usinggit add --patch
(orgit add -p
),--staged
will return what is staged.If you have more than one file with staged changes, it may more practical to use
git add -i
, then select6: diff
, and finally pick the file(s) you are interested in.