在暂存区的文件上显示 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

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

Show git diff on file in staging area

gitgit-diffgit-stage

提问by arod

Is there a way I can see the changes that were made to a fileafter 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 --cachedflag:

您可以显示已使用--cached标志暂存的更改:

$ git diff --cached

In more recent versions of git, you can also use the --stagedflag (--stagedis 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 -–stagedoption 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 fileto show the diff for a specific file.

您还可以git diff HEAD file用于显示特定文件的差异。

See the EXAMPLEsection under git-diff(1)

请参阅下面的EXAMPLE部分git-diff(1)