在使用 SourceTree 的过程中,你可能会遇到这样诡异的事情,把一个 SubmoduleA 右击删除后,再添加一个SubmoduleB,竟然怎么都显示不出来???正常情况下把鼠标移到 SUBMODULES 标签上 会有 Show/Hide 按钮,点击可显示或隐藏具体子模块……难道是我打开的方式不对?
其实,只要在终端输入命令
$ git rm --cached { SubmoduleA 路径}
把 SubmoduleA 移除后,SubmoduleB 就可以正常显示了。
然而,直接右击删除 submodule 方式是无法彻底删除的
正确删除方法在 stackoverflow 上有相关讨论
Via the page Git Submodule Tutorial:
To remove a submodule you need to:
- Delete the relevant section from the
.gitmodulesfile. - Stage the
.gitmoduleschangesgit add .gitmodules - Delete the relevant section from
.git/config. - Run
git rm --cached path_to_submodule(no trailing slash). - Run rm -rf
.git/modules/path_to_submodule - Commit
git commit -m "Removed submodule <name>" - Delete the now untracked submodule files
rm -rf path_to_submodule
参考
SourceTree does not show submodules
How do I remove a submodule?