如何删除Git子模块?为什么我不能git子模块rm模块名称?


当前回答

对于数字2.17及以上,它只是:

git submodule deinit -f {module_name}
git add {module_name}
git commit

其他回答

对于数字2.17及以上,它只是:

git submodule deinit -f {module_name}
git add {module_name}
git commit

要删除添加的子模块,请使用:

REPOSITORY=blah@blah.com:repos/blah.git
MOD_DIR=lib/blah
git submodule add $REPOSITORY $MOD_DIR

Run:

git rm $MOD_DIR

就是这样。

对于旧版本的git(约为1.8.5,实际上甚至在2.26.2中),请使用:

git submodule deinit $MOD_DIR
git rm $MOD_DIR
git config -f .gitmodules --remove-section submodule.$MOD_DIR

我创建了一个bash脚本来简化删除过程。它还检查回购中是否有未保存的更改,并请求确认。它已经在os x上进行了测试,如果知道它在普通linux发行版上是否也能正常工作,将会很有趣:

https://gist.github.com/fabifrank/cdc7e67fd194333760b060835ac0172f

除了这些建议之外,我还必须rm-Rf.git/modules/path/to/submodule,才能添加一个同名的新子模块(在我的例子中,我用原来的fork替换了一个fork)

我遵循了同一指南的指示如何删除子模块?

$ git submodule deinit -f <submodule-name>
$ rm -rf .git/modules/<submodule-name>
$ git config -f .gitmodules --remove-section submodule.<submodule-name>
$ git config -f .git/config --remove-section submodule.<submodule-name>
$ git rm --cached <submodule-name>
$ git commit -m 'rm submodule: <submodule-name>'

但它一直在说:

fatal: no submodule mapping found in .gitmodules for path

因此,我所做的是像这样在.gitignore中包含路径(路径末尾没有星号):

<path>

然后我修改了任何文件并进行了简单的推送:

$ git add .
$ git commit -m "Ignoring sharedlibs folder <path> on .gitignore"
$ git push -u origin master