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


当前回答

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

其他回答

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

我最近发现了一个git项目,其中包含许多有用的git相关命令:https://github.com/visionmedia/git-extras

安装并键入:

git-delete-submodule submodule

然后事情就完成了。子模块目录将从repo中删除,并且仍然存在于文件系统中。然后可以提交更改,如:gitcommit-am“Remove the submodule”。

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

git rm --cached path/to/submodule

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

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

cd submodule
rm -fr .git

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

这个问题的大多数答案都过时、不完整或不必要的复杂。

使用git 1.7.8或更高版本克隆的子模块将在您的本地存储库中最多留下四条自己的痕迹。删除这四个轨迹的过程由以下三个命令给出:

# Remove the submodule entry from .git/config
git submodule deinit -f path/to/submodule

# Remove the submodule directory from the superproject's .git/modules directory
rm -rf .git/modules/path/to/submodule

# Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule
git rm -f path/to/submodule