如何删除Git子模块?为什么我不能git子模块rm模块名称?
当前回答
所有的答案看起来都过时了。我使用的是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)
其他回答
使用git v2.7.4,简单的3个步骤就可以了。
git submodule deinit -f -- a/submodule
git rm -f a/submodule
git commit
2012年12月我正在做的事情(结合了这些答案中的大部分):
oldPath="vendor/example"
git config -f .git/config --remove-section "submodule.${oldPath}"
git config -f .gitmodules --remove-section "submodule.${oldPath}"
git rm --cached "${oldPath}"
rm -rf "${oldPath}" ## remove src (optional)
rm -rf ".git/modules/${oldPath}" ## cleanup gitdir (optional housekeeping)
git add .gitmodules
git commit -m "Removed ${oldPath}"
我发现deinit对我很好:
git submodule deinit <submodule-name>
git rm <submodule-name>
从git文档:
解交织注销给定子模块,即删除整个子模块$名称git/config中的部分及其工作树。
对于数字2.17及以上,它只是:
git submodule deinit -f {module_name}
git add {module_name}
git commit
以下是我所做的:
1.)从.gitmodules文件中删除相关部分。您可以使用以下命令:
git config -f .gitmodules --remove-section "submodule.submodule_name"
2.)准备.gitmodules更改
git add .gitmodules
3.)从.git/config中删除相关部分。您可以使用以下命令:
git submodule deinit -f "submodule_name"
4.)删除gitlink(无尾斜杠):
git rm --cached path_to_submodule
5.)清理.git/模块:
rm -rf .git/modules/path_to_submodule
6.)承诺:
git commit -m "Removed submodule <name>"
7.)删除现在未跟踪的子模块文件
rm -rf path_to_submodule
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别