我通过编辑
.gitmodules
手动删除和添加子模块,但是执行git submodule update --init --recursive
仅克隆之前存在的moduleA,我手动添加的子模块未克隆。运行 git submodule
还会显示已被错误删除的旧子模块
fatal: no submodule mapping found in .gitmodules for path 'moduleOld'
而
git submodule sync
仅再次显示moduleA。有办法解决这个问题吗?
您不应该通过编辑
.gitmodules
来手动添加/删除子模块,因为 git 还会跟踪 .git/config 文件中的条目。尝试删除子模块并在终端中提交。然后添加新的子模块。要删除子模块,请尝试:
git rm --cached path/to/submodule #updates Git to stop tracking the submodule
rm -rf path/to/submodule #removes the submodule files locally
git commit -m 'Remove submodule'
然后添加一个新的子模块尝试:
git submodule add <repository> <path>
git submodule update --init --recursive
如果您手动更改
.gitmodules
,我相信运行同步将同步 .git/config 中的 URL:
git submodule sync