合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
[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 ```