gpt4 book ai didi

git - 如何显示暂存删除文件的差异?

转载 作者:太空狗 更新时间:2023-10-29 12:57:29 26 4
gpt4 key购买 nike

这是状态:

On branch howard
Your branch is up-to-date with 'origin/howard'.

Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

deleted: thing.scala
(and other changed files)

如果我执行 git diff --cached,它会显示 thing.scala 的内容以及其他差异。

但我只想查看已删除文件的内容。如何在 git 中这样做?

以下尝试无效:

git show HEAD~1 thing.scala
git diff --cached thing.scala

最佳答案

您的第一种方法,即

git show HEAD~1 thing.scala

几乎是对的,只是有两个小问题。

首先,由于您还没有提交,最后一个版本仍然有 thing.scala文件是 HEAD . HEAD~1是之前的版本。

其次,显示来自特定提交的文件的语法是 git show <commit>:<file> .

所以正确的命令是:

git show HEAD:thing.scala

文档在 gitrevisions 中提到了此语法:

<rev>:<path>, e.g. HEAD:README, :README, master:./README

A suffix : followed by a path names the blob or tree at the given path in the tree-ish object named by the part before the colon. :path (with an empty part before the colon) is a special case of the syntax described next: content recorded in the index at the given path. A path starting with ./ or ../ is relative to the current working directory. The given path will be converted to be relative to the working tree’s root directory. This is most useful to address a blob or tree from a commit or tree that has the same tree structure as the working tree.

至于git diff --cached : 只有当它们作为文件存在时,后面的参数才会被解释为文件名。由于您删除了该文件,因此不适用。您可以使用 -- 强制将参数解释为文件名。 :

git diff --cached -- thing.scala

关于git - 如何显示暂存删除文件的差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21376171/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com