在 git 中查看分阶段更改的差异

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5250650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:19:08  来源:igfitidea点击:

View diff of staged changes in git

gitgit-diff

提问by Daniel DiPaolo

Possible Duplicate:
How do I show the changes which have been staged?

可能的重复:
如何显示已上演的更改?

Is there a simple way to view the diff of only the stagedchanges I have pending in git? I've staged several files but want to take one last look at what I'm committing before I push the button. I have several other unstaged changes that I want to go in a separate commit, so unstaging, doing git diff, and then paging through to the file I want isn't all that desirable an option.

有没有一种简单的方法可以查看我在 git 中挂起的分阶段更改的差异?我已经上演了几个文件,但想在按下按钮之前最后看看我正在提交的内容。我还有其他几个未暂存的更改,我想在单独的提交中进行,因此取消暂存,执行git diff,然后分页到我想要的文件并不是一个理想的选择。

Example:

例子:

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   foo.java
#
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   bar.java
#       modified:   baz.java
#       modified:   qux.java

I really just want to see what I changed in foo.javawithout having to unstage.

我真的只想看看我改变了什么,foo.java而不必取消。

回答by Daniel DiPaolo

One more minute of Googling found the answer of course, answering my own question:

一分钟的谷歌搜索当然找到了答案,回答了我自己的问题:

git diff --cached