在暂存区域中的文件上显示 git diff

发布于 2024-09-15 17:17:40 字数 165 浏览 10 评论 0原文

有没有办法可以在完成 git add file 后查看对文件所做的更改?

也就是说,当我这样做时:

git add file
git diff file

没有显示差异。我想有一种方法可以查看自上次提交以来的差异,但我不知道那是什么。

Is there a way I can see the changes that were made to a file after I have done 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

相权↑美人 2024-09-22 17:17:41

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

$ git diff --cached

在较新版本的 git 中,您还可以使用 --staged 标志(- -staged--cached 的同义词):

$ git diff --staged

You can show changes that have been staged with the --cached flag:

$ git diff --cached

In more recent versions of git, you can also use the --staged flag (--staged is a synonym for --cached):

$ git diff --staged
信仰 2024-09-22 17:17:41

为了查看已经暂存的更改,您可以将 --staged 选项传递给 git diff (在 1.6 之前的 Git 版本中,使用 –-缓存)。

git diff --staged
git diff --cached

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).

git diff --staged
git diff --cached
浅忆流年 2024-09-22 17:17:41

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

请参阅 git-diff(1)EXAMPLE 部分代码>

You can also use git diff HEAD file to show the diff for a specific file.

See the EXAMPLE section under git-diff(1)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文