【发布时间】:2021-08-20 23:35:12
【问题描述】:
在同一个文件上使用 'git ls-files -s' 和 'git log' 时,我得到不同的 SHA 哈希值。以 repo https://github.com/preservim/nerdtree 中的文件 lib/nerdtree/nerdtree.vim 为例,标签 6.10.5。
命令git log lib/nerdtree/nerdtree.vim 产生,
commit 593c16add35a5461f189b8189abe219f7bbbd604 (tag: 6.10.5)
但是命令git ls-files -s lib/nerdtree/nerdtree.vim 产生,
100644 61a11a96ba44c7b1bf0472b598f2c967b2dce9f2 0 lib/nerdtree/nerdtree.vim
如果我尝试检查 'git log' 返回的 SHA,则该命令成功。如果我尝试检查 'git ls-files -s' 返回的 SHA,则会产生致命错误:
git checkout 61a11a96ba44c7b1bf0472b598f2c967b2dce9f2 lib/nerdtree/nerdtree.vim
fatal: reference is not a tree: 61a11a96ba44c7b1bf0472b598f2c967b2dce9f2
为什么 'git ls-files -s' 和 'git log' 会为同一个文件生成不同的 SHA 哈希?
注意:我四处寻找答案并找到了这个帖子:Git - finding the SHA1 of an individual file in the index。该线程解释了为什么'git hash-object'和'git ls-files -s'的输出之间可能存在差异,但它没有解释'git ls-files -s'和'git的输出之间的差异记录”。
【问题讨论】:
-
阅读git-scm.com/book/en/v2/Git-Internals-Plumbing-and-Porcelain,了解有关 Git 存储库中存在的各种对象以及如何使用它们来实现源代码控制系统的更多信息。
-
@chepner 我没有意识到 GIT 中有文件对象和提交对象。这对我有帮助:git-scm.com/book/en/v2/Git-Internals-Git-Objects
-
抱歉,这才是我真正想要发送的链接。我没有仔细查看目录,看不到第 10 章的那个部分有一个单独的链接。很高兴它有帮助!