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