2017-04-13 86 views
0

commit对象我只是做了一些(不是我)回购git ls-tree,看到此输出:混帐:在git的LS-树输出

100644 blob 54cfbdae80000000000000000000639faa8ecaee .gitignore 
100644 blob 7c6a8bf6500000000000000000000c84e3fba06d xxx.py 
040000 tree f9c9cf0760000000000000000000c6c48116bc14 yyy 
160000 commit 6f473ed0000000000000000000dffd4ebd48d103 zzz 
040000 tree fb81e98c40000000000000000000f90685a62410 vvv 
040000 tree 642e5f2e3000000000000000000063acd187d42d uuu 

zzz是空目录。如果我删除它,它会在git status输出中显示为更改。 git status如果我触摸其中的某些文件,则看不到任何内容。

什么是zzz?那怎么可能?

回答

1

虽然zzz项创建一个目录,它是意味着代表目录。看到这个的关键是将其typemode与其他目录进行比较。 zzz的模式为160000,其类型为commit;最终存储非空目录的树对象yyy,vvvuuu具有模式040000和类型tree

这意味着zzz条目是一个所谓的“gitlink”。

关联的哈希ID(显然你是上面提到的那些;它们有太多的零是巧合)是Git应该检查到该目录中的子模块的哈希。 Git会将目录本身作为检查这个超级项目的一部分。但是,稍后Git会读取.gitmodules配置文件以找到合适的子项目URL:当您执行git submodule init时,它会将该存储库克隆到zzz目录中。

如果您使用git clone --recursive进行克隆,您可以让Git在超级项目的git clone期间自动执行此操作。详情请参阅How to `git clone` including submodules?

又见Where does Git store the SHA1 of the commit for a submodule?

注意,如果没有为路径没有.gitmodules项,Git不会知道这里克隆。 These "fake" entries may therefore be (ab)used to create empty directories. It sort-of works. There are no promises that it will keep working in later versions of Git, though, and in any case Git just kind of loses track of files within here, as it thinks they belong to another repository. Most of this paragraph is a link to the answer that describes this in detail.

+0

我甚至没有考虑子模块......虽然没有'.gitmodules'。 –

+1

如果在任何地方没有'.gitmodules'文件,Git将不知道要克隆什么。这可能是某人让Git创建一个空子目录的诀窍 - 但它并不奏效,因为Git坚持认为它应该找到一个子模块。请参阅[此答案](http://stackoverflow.com/a/8944077/1256452)。 – torek