在暂存区的文件上显示 git diff
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3527856/
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
Show git diff on file in staging area
提问by arod
Is there a way I can see the changes that were made to a file
after I have done git add file
?
有没有办法可以看到file
我完成后对 a 所做的更改git add file
?
That is, when I do:
也就是说,当我这样做时:
git add file
git diff file
no diff is shown. I guess there's a way to see the differences since the last commit but I don't know what that is.
没有显示差异。我想有一种方法可以看到自上次提交以来的差异,但我不知道那是什么。
回答by mipadi
You can show changes that have been staged with the --cached
flag:
您可以显示已使用--cached
标志暂存的更改:
$ git diff --cached
In more recent versions of git, you can also use the --staged
flag (--staged
is a synonym for --cached
):
在最新版本的 git 中,您还可以使用--staged
标志(--staged
是 的同义词--cached
):
$ git diff --staged
回答by Arturo Herrero
In order to see the changes that have been staged already, you can pass the -–staged
option to git diff
(in pre-1.6 versions of Git, use –-cached
).
为了查看已经暂存的更改,您可以将-–staged
选项传递给git diff
(在 Git 1.6 之前的版本中,使用–-cached
)。
git diff --staged
git diff --cached
回答by J-16 SDiZ
You can also use git diff HEAD file
to show the diff for a specific file.
您还可以git diff HEAD file
用于显示特定文件的差异。
See the EXAMPLE
section under git-diff(1)
请参阅下面的EXAMPLE
部分git-diff(1)