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


当前回答

这对我有用。上面的答案在终端中显示了这一点,没有发生其他事情

'fatal: not removing 'demolibapp' recursively without -r'

demolibapp是我要删除的子模块名称git子模块deinit分解git rm—缓存的demolibapp-rrm-rf.git/modules/demolibappgit add--全部gitcommit-m“删除额外的子模块”数字推送rm-rf脱模剂

其他回答

我发现deinit对我很好:

git submodule deinit <submodule-name>    
git rm <submodule-name>

从git文档:

解交织注销给定子模块,即删除整个子模块$名称git/config中的部分及其工作树。

从git中删除子模块的最佳方法:

$ 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>'

使用git v2.7.4,简单的3个步骤就可以了。

git submodule deinit -f -- a/submodule    
git rm -f a/submodule
git commit

我不得不进一步执行John Douth的步骤,并将其cd到子模块的目录中,然后删除Git存储库:

cd submodule
rm -fr .git

然后,我可以将文件作为父Git存储库的一部分提交,而无需对子模块的旧引用。

所有的答案看起来都过时了。我使用的是git版本2.28.0。一行回答是,

git rm path-to-submodule

然而,即使从源代码管理中删除了子模块,.git/modules/path到子模块仍然包含子模块存储库,.git/config包含其URL,因此您仍然需要手动删除这些子模块:

git config --remove-section submodule.path-to-submodule
rm -rf .git/modules/path-to-submodule

有时,必须使用-f标志:

$ git rm -f img2vec

例如,因为您可能会收到如下错误:

$ git rm img2vec/
error: the following file has changes staged in the index:
    img2vec
(use --cached to keep the file, or -f to force removal)