1
我已经熟悉了一下git内部和不同的git对象。我有一个简单的存储库,在顶层目录中有一个.txt文件,在名为'my-directory'的目录中有两个.txt文件(file1.txt和file2.txt),以及名为'my-submodule'的子模块。当我尝试运行$ git cat-file -p {submodule git commit object SHA-1}
时出现错误,我无法弄清楚原因。我在下面展示我正在运行的所有命令,并希望有人能帮助我。当使用'git cat-file -p'时子模块提交对象'Not a valid object name'
$ git cat-file -p master
tree fcc88590212b42b31803217036a93a9edfe4af1c
parent ae767cc2edd396e63f127d4f3354f769645a3dc4
author Martin
committer Martin
Awesome commit
$ git cat-file -p fcc88590212b42b31803217036a93a9edfe4af1c
100644 blob 21735012b86a0c6c266eb7fb629a777ca70848c1 my-file.txt
040000 tree 4df930165b3c59c0f5dc134ed76d889e4d177d2f my-directory
160000 commit 93a431b481f9ca2b498c94b0c0641e54f00322e0 my-submodule
$ git cat-file -p 21735012b86a0c6c266eb7fb629a777ca70848c1
This is the content of 'my-file.txt'
$ git cat-file -p 4df930165b3c59c0f5dc134ed76d889e4d177d2f
100644 file1.txt
100644 file2.txt
$ git cat-file -p 93a431b481f9ca2b498c94b0c0641e54f00322e0
fatal: Not a valid object name 93a431b481f9ca2b498c94b0c0641e54f00322e0
每个“树”条目都包含这些模式字符串(字面上,ASCII文本);他们告诉Git关于目标对象的*假设*。但是,每个对象都有自己的类型嵌入其中,因此可能存在兼容性问题。 blob对象是模式'100644'和'100755'(文件)的有效查找结果,例如'120000'(符号链接)也是有效的查找结果;但没有其他对象类型对于这三种模式是有效的。无论如何,这只是边注:正如你所说,gitlink中的提交哈希是* other repository *中的哈希ID。 – torek
@torek看起来你是对的,它会检查'mode == 160000'来识别子模块:https://github.com/git/git/blob/b14f27f91770e0f99f64135348977a0ce1c7993a/git-submodule.sh#L882 – kan