在使用 SourceTree 的過程中,你可能會遇到這樣詭異的事情,把一個 SubmoduleA 右擊刪除后,再添加一個SubmoduleB,竟然怎么都顯示不出來???正常情況下把鼠標(biāo)移到 SUBMODULES 標(biāo)簽上 會有 Show/Hide 按鈕,點(diǎn)擊可顯示或隱藏具體子模塊……難道是我打開的方式不對?
其實(shí),只要在終端輸入命令
$ git rm --cached { SubmoduleA 路徑}
把 SubmoduleA 移除后,SubmoduleB 就可以正常顯示了。
然而,直接右擊刪除 submodule 方式是無法徹底刪除的
正確刪除方法在 stackoverflow 上有相關(guān)討論
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?