坑:
在一个文件夹下,git clone
一个子模块,然后再把这个文件夹init
并add .
,会出现错误,执行过程如下:
cd try2
git clone git@192.168.10.30:Algorithm4/Programs/ADC/modules/ITP/aoi_info.git
git init
git add .
#warning: 正在添加嵌入式 git 仓库:aoi_info
#提示:You have added another git repository inside your current repository.
#提示:Clones of the outer repository will not contain the contents of
#提示:the embedded repository and will not know how to obtain it.
#提示:If you meant to add a submodule, use:
#提示:
#提示: git submodule add <url> aoi_info
#提示:
#提示:If you added this path by mistake, you can remove it from the
#提示:index with:
#提示:
#提示: git rm --cached aoi_info
#提示:
#提示:See "git help submodule" for more information.
解法:
以后避免这种情况,可以先将母文件夹git init
了,然后git submodule add [url]
即可,那么add
、commit
、push
都没有问题了。
值得注意的是,如果将这种存储库push
到云端,然后再pull
或者clone
回来,那么会发现aoi_info
子模块内容为空,这是因为repoA
下嵌入了一个repoB
,所以需要执行git submodule update --init --recursive
把子仓库内容拉过来。