git 删除子模块
For many git-based projects, submodules are useful in avoiding duplicate work and easing utility library updates. There are times, however, when a submodule needs to be removed from a project. Submodules aren’t removed with git rm submoduledir, they must be removed in a more tedious, manual fashion. There are many unclear explanations of how to remove a submodule but I found one on Stack Overflow that’s concise, so I thought I’d share it. The steps are as follows:
对于许多基于git的项目,子模块可用于避免重复工作并简化实用程序库更新。 但是,有时需要从项目中删除子模块。 不能使用git rm submoduledir删除子模块,而必须以更繁琐,手动的方式删除它们。 关于如何删除子模块有很多不清楚的解释,但是我在Stack Overflow上找到了一个简洁明了的解释,因此我想与大家分享。 步骤如下:
-
Delete the relevant section from the
.gitmodules
file. The section would look similar to:从
.gitmodules
文件中删除相关部分。 该部分看起来类似于:[submodule "vendor"] path = vendor url = git://github.com/some-user/some-repo.git
-
Stage the
.gitmodules
changes via command line using:git add .gitmodules
使用以下命令通过命令行
git add .gitmodules
.gitmodules
更改:git add .gitmodules
-
Delete the relevant section from
.git/config
, which will look like:从
.git/config
删除相关部分,如下所示:[submodule "vendor"] url = git://github.com/some-user/some-repo.git
-
Run
git rm --cached path/to/submodule
. Don’t include a trailing slash — that will lead to an error.运行
git rm --cached path/to/submodule
。 请勿在结尾加上斜线-否则会导致错误。 -
Run
rm -rf .git/modules/submodule_name
运行
rm -rf .git/modules/submodule_name
- Commit the change:
提交更改:
-
Delete the now untracked submodule files
rm -rf path/to/submodule
删除现在未跟踪的子模块文件
rm -rf path/to/submodule
Those steps will get you rid of that unwanted submodule. A lot harder than adding one, eh?
这些步骤将使您摆脱不必要的子模块。 比加一个难得多,是吗?
git 删除子模块