[TOC]
有时子模块的项目维护地址发生了变化,或者需要替换子模块,就需要删除原有的子模块。
## 操作方法
删除子模块较复杂,步骤如下:
```
rm -rf 子模块目录 删除子模块目录及源码
vi .gitmodules 删除项目目录下.gitmodules文件中子模块相关条目
vi .git/config 删除配置项中子模块相关条目
rm .git/modules/* 删除模块下的子模块目录,每个子模块对应一个目录,注意只删除对应的子模块目录即可
```
执行完成后,再执行添加子模块命令即可,如果仍然报错,执行如下:
```
git rm --cached 子模块名称
```
完成删除。
## 举例
>注:做删除前我们先备份一下,我们要删除全部`.gitmodules`
如果有多个分支,在每个分支都这么操作一下!
我们做如下操作:
### 第一步:删除子模块目录
```
rm -rf simplewind/extend
rm -rf simplewind/vendor
rm -rf simplewind/thinkphp
rm -rf public/plugins
```
### 第二步:删除子模块配置
```
rm -rf .gitmodules
```
### 第三步:修改git主配置文件
```
vim .git/config
```
原文件是:
```
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = false
[remote "origin"]
url = https://gitee.com/sxctkj/tmc.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "develop"]
remote = origin
merge = refs/heads/develop
[submodule "simplewind/thinkphp"]
active = true
url = https://gitee.com/liu21st/framework
[submodule "public/plugins"]
active = true
url = https://gitee.com/hongweizhiyuan/thinkcmf5-plugins
[submodule "simplewind/extend"]
active = true
url = https://gitee.com/hongweizhiyuan/thinkcmf5-extend
[submodule "simplewind/vendor"]
active = true
url = https://gitee.com/hongweizhiyuan/thinkcmf5-vendor
[pull]
rebase = true
[branch "release1.0"]
remote = origin
merge = refs/heads/release1.0
[branch "release2.0"]
remote = origin
merge = refs/heads/release2.0
```
修改文件删除`submodule`后是:
```
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = false
[remote "origin"]
url = https://gitee.com/sxctkj/tmc.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "develop"]
remote = origin
merge = refs/heads/develop
[pull]
rebase = true
[branch "release1.0"]
remote = origin
merge = refs/heads/release1.0
[branch "release2.0"]
remote = origin
merge = refs/heads/release2.0
```
### 第三步:删除子模块儿配置全部文件
```
rm -rf .git/modules
```
### 第四步:清除子模块儿缓存
```
git rm --cached simplewind/extend
git rm --cached simplewind/vendor
git rm --cached simplewind/thinkphp
git rm --cached public/plugins
```
### 第五步:忽略文件
```
vim .gitignore
```
去掉
```
simplewind/vendor
simplewind/extend
```
- 其他
- Git submodule 如何删除一个 submodule
- 解 git submodule 无映射路径的问题
- 删除分支
- git revert
- 基本命令
- git reset的三种模式
- ignore的使用
- git tag
- 用户相关
- 问题
- 重命名远程分支
- 注意事项
- GIT里设置大小写敏感
- 如何处理git每次提交都输入密码
- Git 工作流程
- 详细使用
- git 放弃更改
- 子模块儿
- 增加子模块儿
- 删除子模块儿
- 更新子模块儿
- 分支
- 分支(branch)操作
- git删除远程分支和本地分支
- 项目属于哪个分支
- 标签(tag)操作
- 命令
- branch
- remote
- clone
- tag
- log
- reflog
- diff
- reset
- merge
- push
- pull
- submodule
- 分支命名