如何删除Git子模块?为什么我不能git子模块rm模块名称?
当前回答
使用Magit的简单解决方案
如果您在Emacs下使用Magit,则可以执行以下操作:
转到项目根目录,然后
M-x,magit列表子模块
then
M-x,删除magit子模块
系统将询问您要删除哪个子模块。
就是这样!
(我的Magit版本是v3.3.0)
其他回答
您可以使用别名自动化其他人提供的解决方案:
[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
使用git v2.7.4,简单的3个步骤就可以了。
git submodule deinit -f -- a/submodule
git rm -f a/submodule
git commit
对于数字2.17及以上,它只是:
git submodule deinit -f {module_name}
git add {module_name}
git commit
我最近发现了一个git项目,其中包含许多有用的git相关命令:https://github.com/visionmedia/git-extras
安装并键入:
git-delete-submodule submodule
然后事情就完成了。子模块目录将从repo中删除,并且仍然存在于文件系统中。然后可以提交更改,如:gitcommit-am“Remove the submodule”。
只是一张纸条。从git1.8.5.2开始,有两个命令可以执行:
git rm -r the_submodule
rm -rf .git/modules/the_submodule
正如@Mark Cheverton的回答正确指出的那样,如果没有使用第二行,即使您现在删除了子模块,剩余的.git/modules/the_submodule文件夹也将阻止将来添加或替换相同的子模块。此外,正如@VonC所提到的,gitrm将在子模块上完成大部分工作。
--更新(07/05/2017)--
为了澄清,_submodule是项目中子模块的相对路径。例如,如果子模块位于子目录subdir内,则为subdir/my_submodule。
正如评论和其他答案中正确指出的,这两个命令(虽然功能上足以删除子模块)确实在.git/config的[submodule“the_submodule”]部分留下了痕迹(截至2017年7月),可以使用第三个命令删除:
git config -f .git/config --remove-section submodule.the_submodule 2> /dev/null
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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之间的区别