How does git manage directories

后端 未结 2 2011
攒了一身酷
攒了一身酷 2021-01-23 10:32

I know git will not see am empty dir but can someone provide a reference to some documentation on how exactly it is implemented. It\'s not only about empty folders. If I add a f

2条回答
  •  闹比i
    闹比i (楼主)
    2021-01-23 11:02

    There are two levels to what’s going on: there’s what happens under the hood (plumbing) and what you actually see (porcelain).

    To learn all about the plumbing layer, I recommend checking out this section of Pro Git. In short, a directory is stored as a tree object with contents like

    100644 blob a906cb2a4a904a152e80877d4088654daad0c859      README
    100644 blob 8f94139338f9404f26296befa88755fc2598c289      Rakefile
    040000 tree 99f1a6d12cb4b6f19c8655fca46c3ecf317074e0      lib
    

    The first column is for permissions, the second column is for whether it’s a blob (a file) or a tree (another directory), the third column is for the SHA-1 of the object, and the last column is the filename.

    Although there’s nothing on the plumbing side preventing you from putting an empty tree object in a commit, it can cause problems later. If you want to achieve a similar effect, you can put a file in the directory. If you want to force the directory to remain empty, you can use this solution; if you don’t care if people put files in later, it can be a README or an empty .gitignore.

提交回复
热议问题