如何删除Git子模块?为什么我不能git子模块rm模块名称?
当前回答
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}"
其他回答
我不得不进一步执行John Douth的步骤,并将其cd到子模块的目录中,然后删除Git存储库:
cd submodule
rm -fr .git
然后,我可以将文件作为父Git存储库的一部分提交,而无需对子模块的旧引用。
删除git子模块
要删除git子模块,需要以下4个步骤。
删除.gitmodules文件中的相应条目。条目可能如下所述
[submodule "path_to_submodule"]
path = path_to_submodule
url = url_path_to_submodule
阶段更改gitadd.gitmodules删除子模块目录git-rm-cached<path_to_submodule>。提交gitcommit-m“Removed submodule xxx”并推送。
下面提到的另外两个步骤需要完全清除本地克隆副本中的子模块。
删除.git/config文件中的相应条目。条目可能如下所述
[submodule "path_to_submodule"]
url = url_path_to_submodule
执行rm-rf.git/modules/path_to_submodule
第5步和第6步不会产生任何需要提交的更改。
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}"
总而言之,这是您应该做的:
设置path_to_submodule变量(无尾随斜杠):
path_to_submodule=path/to/submodule
从.gitmodules文件中删除相关行:
git config -f .gitmodules --remove-section submodule.$path_to_submodule
从.git/config中删除相关部分
git config -f .git/config --remove-section submodule.$path_to_submodule
仅从索引中取消存储并删除$path_to_submodule(以防止丢失信息)
git rm --cached $path_to_submodule
跟踪对.gitmodules所做的更改
git add .gitmodules
提交超级项目
git commit -m "Remove submodule submodule_name"
删除现在未跟踪的子模块文件
rm -rf $path_to_submodule
rm -rf .git/modules/$path_to_submodule
另请参见:备选指导线
要删除添加的子模块,请使用:
REPOSITORY=blah@blah.com:repos/blah.git
MOD_DIR=lib/blah
git submodule add $REPOSITORY $MOD_DIR
Run:
git rm $MOD_DIR
就是这样。
对于旧版本的git(约为1.8.5,实际上甚至在2.26.2中),请使用:
git submodule deinit $MOD_DIR
git rm $MOD_DIR
git config -f .gitmodules --remove-section submodule.$MOD_DIR
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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之间的区别