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


当前回答

我发现deinit对我很好:

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

从git文档:

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

其他回答

如果您刚刚添加了子模块,例如,您只是添加了错误的子模块或将其添加到了错误的位置,只需执行git stash,然后删除文件夹。这是假设添加子模块是您在最近的回购中唯一做的事情。

总而言之,这是您应该做的:

设置path_to_submodule变量(无尾随斜杠):

path_to_submodule=path/to/submodule

从.gitmodules文件中删除相关行:

git config -f .gitmodules --remove-section submodule.$path_to_submodule

从.git/config中删除相关部分

git config -f .git/config --remove-section submodule.$path_to_submodule

仅从索引中取消存储并删除$path_to_submodule(以防止丢失信息)

git rm --cached $path_to_submodule

跟踪对.gitmodules所做的更改

git add .gitmodules

提交超级项目

git commit -m "Remove submodule submodule_name"

删除现在未跟踪的子模块文件

rm -rf $path_to_submodule

rm -rf .git/modules/$path_to_submodule

另请参见:备选指导线

如果你想删除子模块而不从本地文件系统中删除文件夹,我可以这样做:

MOD=example
git rm --cached -f apps/$MOD
git config -f .gitmodules --remove-section submodule.$MOD

git子模块deinit<子模块路径>从.gitmodules中删除节git rm<子模块路径>删除需要从项目中删除的模块文件。将删除的文件添加到git并调用gitadd.gitmodules提交并推送

我发现deinit对我很好:

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

从git文档:

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