如何删除Git子模块?为什么我不能git子模块rm模块名称?
当前回答
这对我有用。上面的答案在终端中显示了这一点,没有发生其他事情
'fatal: not removing 'demolibapp' recursively without -r'
demolibapp是我要删除的子模块名称git子模块deinit分解git rm—缓存的demolibapp-rrm-rf.git/modules/demolibappgit add--全部gitcommit-m“删除额外的子模块”数字推送rm-rf脱模剂
其他回答
在这个网站上尝试了所有不同的答案后,我最终得到了这个解决方案:
#!/bin/sh
path="$1"
if [ ! -f "$path/.git" ]; then
echo "$path is no valid git submodule"
exit 1
fi
git submodule deinit -f $path &&
git rm --cached $path &&
rm -rf .git/modules/$path &&
rm -rf $path &&
git reset HEAD .gitmodules &&
git config -f .gitmodules --remove-section submodule.$path
这将恢复与添加子模块之前完全相同的状态。您可以立即再次添加子模块,这在大多数答案中是不可能的。
git submodule add $giturl test
aboveScript test
这将使您得到一个干净的签出,无需提交任何更改。
这是用以下方法测试的:
$ git --version
git version 1.9.3 (Apple Git-50)
我最近发现了一个git项目,其中包含许多有用的git相关命令:https://github.com/visionmedia/git-extras
安装并键入:
git-delete-submodule submodule
然后事情就完成了。子模块目录将从repo中删除,并且仍然存在于文件系统中。然后可以提交更改,如:gitcommit-am“Remove the submodule”。
从git中删除子模块的最佳方法:
$ git submodule deinit -f <submodule-name>
$ rm -rf .git/modules/<submodule-name>
$ git config -f .gitmodules --remove-section submodule.<submodule-name>
$ git config -f .git/config --remove-section submodule.<submodule-name>
$ git rm --cached <submodule-name>
$ git commit -m 'rm submodule: <submodule-name>'
以下是我所做的:
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
总而言之,这是您应该做的:
设置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
另请参见:备选指导线
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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之间的区别