How do I show the changes which have been staged?

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?


It should just be:

git diff --cached

--cached means show the changes in the cache/index (ie staged changes) against the current HEAD . --staged is a synonym for --cached .

--staged and --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:

简单的Git差异

git diff

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.

Also :

There is a bit more detail on 365Git.


If you'd be interested in a visual side-by-side view, the diffuse visual diff tool can do that. It will even show three panes if some but not all changes are staged. In the case of conflicts, there will even be four panes.

漫画与分阶段和非分期编辑截图

Invoke it with

diffuse -m

in your Git working copy.

If you ask me, the best visual differ I've seen for a decade. Also, it is not specific to Git: It interoperates with a plethora of other VCS, including SVN, Mercurial, Bazaar, ...

See also: Show both staged & working tree in git diff?

链接地址: http://www.djcxy.com/p/1446.html

上一篇: 什么是.NET中的“闭包”?

下一篇: 我如何显示已经上演的变化?