如何删除Git子模块?为什么我不能git子模块rm模块名称?
当前回答
这个问题的大多数答案都过时、不完整或不必要的复杂。
使用git 1.7.8或更高版本克隆的子模块将在您的本地存储库中最多留下四条自己的痕迹。删除这四个轨迹的过程由以下三个命令给出:
# Remove the submodule entry from .git/config
git submodule deinit -f path/to/submodule
# Remove the submodule directory from the superproject's .git/modules directory
rm -rf .git/modules/path/to/submodule
# Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule
git rm -f path/to/submodule
其他回答
如果你想删除子模块而不从本地文件系统中删除文件夹,我可以这样做:
MOD=example
git rm --cached -f apps/$MOD
git config -f .gitmodules --remove-section submodule.$MOD
我刚刚找到了.submodule(忘记了确切名称)隐藏文件,它有一个列表。。。你可以用这种方式逐个删除它们。我刚刚有一个,所以我删除了它。很简单,但它可能会搞乱Git,因为我不知道子模块是否附加了什么。到目前为止,除了libetpan通常的升级问题外,似乎还可以,但这(希望)是无关的。
注意到没有人发布手动擦除,因此添加
删除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步不会产生任何需要提交的更改。
我创建了一个bash脚本来简化删除过程。它还检查回购中是否有未保存的更改,并请求确认。它已经在os x上进行了测试,如果知道它在普通linux发行版上是否也能正常工作,将会很有趣:
https://gist.github.com/fabifrank/cdc7e67fd194333760b060835ac0172f
如果您需要使用bash脚本在一行命令中执行此操作,如下所示:
$cd/path/to/your/rebo&&/bin/bash$HOME/remove_submodule.sh/path/to-the/submodule
在$HOME目录中创建bash脚本文件,名为remove_submodule.sh:
#!/bin/bash
git config -f .gitmodules --remove-section submodule.$1
git config -f .git/config --remove-section submodule.$1
git rm --cached $1
git add .gitmodules
git commit -m "Remove submodule in $1"
rm -rf $1
rm -rf .git/modules/$1
git push origin $(git rev-parse --abbrev-ref HEAD) --force --quiet
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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之间的区别