How does git handle cloning another repository int

2019-05-28 16:45发布

I just cloned a repository into a subdirectory of another repository, and git actually appeared to handle the situation pretty intelligently. I know about submodules, but I thought they always had to be explicitly defined and I didn't think git had this functionality. What happened?

Here's my shell session:

https://gist.github.com/858131

2条回答
神经病院院长
2楼-- · 2019-05-28 17:25

The second repository is being handled as a submodule by the first repository. Since you haven't defined it as a submodule though, you can not interact with it using the git submodule command, but all other commands treat it as a submodule.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-05-28 17:38

It handles it as a nested repository, not as a submodule.
As you found out, to declare it as a submodule:

  • the sub-directory shouldn't already exist, meaning if you already cloned your second repo, you need to delete it first before adding it as a submodule.
  • or you can try adding it directly in the .gitmodules file (not tested)

That will allow for the creation of the special entry in the git index referencing the submodule SHA1, as shown here, and detailed in the SO question "Nested git repositories without submodules?".

查看更多
登录 后发表回答