git - 'git cat-file -p <sha1 >': "fatal : Not a valid object name"on random objects from . git/objects

标签 git

我想了解更多关于 git 内部工作原理的信息,所以我运行了这些命令:

cd .git/objects/62

ls
00cb2f01089db22aca24675272a16712e89747
0ee798881329430bfef6c558be7b14c1f0676f
1087f408e2f2bd782d53a1211a7418fee4f6a7
a6a71f3bd5a3af882f3f0ec4fad4c672055746
f95e69f344b52c5038d922260189475626e69a

git cat-file -p 00cb2f01089db22aca24675272a16712e89747

出现以下错误:

fatal: Not a valid object name 00cb2f01089db22aca24675272a16712e89747

我为什么得到它?

我尝试了大约 10 次(针对 .git/objects 中不同目录中的不同文件)并得到了同样的错误。

如何查看文件的实际内容(无论是 blob、树还是提交)?

最佳答案

您不必 cd 到 .git 对象存储区,但您必须为 Git 提供足够的完整 sha1 哈希来唯一标识该对象。

通常前 6 或 7 位数字就足够了。 Git 从前面开始匹配对象 ID,因此输入任何子字符串(例如最后几位数字)都将失败(或匹配到与您预期不同的对象)。

git cat-file -p 621087f408e2f2bd782d53a1211a7418fee4f6a7

Git 将其对象存储在 .git/objects 中,分布在 256 个文件夹中以减小目录的大小。每个散列的前两个字符用作目录名,其余 38 个字符用作文件名。

关于git - 'git cat-file -p <sha1 >': "fatal : Not a valid object name"on random objects from . git/objects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8149887/

相关文章:

git - 两台笔记本电脑如何在没有互联网的情况下相互推/pull

git - git 功能、发布和修补程序之间有什么区别?

git - 为什么 tortoisemerge 不能用作我的 merge 工具?

git stash list 或 git show ,返回 ( most +s +'/---' : 1: most: not found ) What is this?

git - git add 后自动显示状态

git - 在 Git 克隆之后直接显示为已修改的文件

Git:在其他分支中拆分提交

git - Heroku 推送被拒绝

eclipse - Windows/Linux 上是否有任何 IDE/GUI 支持 git-flow?

git - 如何在 GitHub 的存储库上设置 receive.denyNonFastForwards