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


当前回答

您可以使用别名自动化其他人提供的解决方案:

[alias]
  rms = "!f(){ git rm --cached \"$1\";rm -r \"$1\";git config -f .gitmodules --remove-section \"submodule.$1\";git config -f .git/config --remove-section \"submodule.$1\";git add .gitmodules; }; f"

将其放入git配置中,然后可以执行:git rms path/to/submodule

其他回答

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

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

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

如果您需要使用bash脚本在一行命令中执行此操作,如下所示:

$cd/path/to/your/rebo&&/bin/bash$HOME/remove_submodule.sh/path/to-the/submodule

在$HOME目录中创建bash脚本文件,名为remove_submodule.sh:

#!/bin/bash

git config -f .gitmodules --remove-section submodule.$1
git config -f .git/config --remove-section submodule.$1
git rm --cached $1
git add .gitmodules
git commit -m "Remove submodule in $1"
rm -rf $1
rm -rf .git/modules/$1
git push origin $(git rev-parse --abbrev-ref HEAD) --force --quiet

我刚刚找到了.submodule(忘记了确切名称)隐藏文件,它有一个列表。。。你可以用这种方式逐个删除它们。我刚刚有一个,所以我删除了它。很简单,但它可能会搞乱Git,因为我不知道子模块是否附加了什么。到目前为止,除了libetpan通常的升级问题外,似乎还可以,但这(希望)是无关的。

注意到没有人发布手动擦除,因此添加

您必须删除.gitmodules和.git/config中的条目,并从历史记录中删除模块的目录:

git rm --cached path/to/submodule

如果你在git的邮件列表上写东西,很可能有人会为你编写一个shell脚本。

我发现deinit对我很好:

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

从git文档:

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