平时习惯用tortoisegit操作git,这次想更改一下工程中子模块的地址,发现用tortoisegit无法直接操作,于是上网找解决办法。
原来git并不能直接更改子模块,只能先删除,然后重新添加,而且git也不支持直接删除,只能手动删除配置文件中的内容。
百度一下一堆教程,如下:
1. 编辑.gitmodules,删除对应要删除的submodule的行.
2. 编辑.git/config,删除有对应要删除的submodule的行.
3. 删除命令:
git rm --cached bundle/xxxx (PS:此处最后没有符号 / .)
4. 删除对应的目录:
rm -rf bundle/xxxx
照着网上的办法操作一路没有问题,这样之前的子模块就被删除了,于是就像重新添加。
用tortoisegit菜单中的submodule add,输入源地址和目标路径,确定后提示了一个错误,如下:
'components/modem' already exists in the index
git did not exit cleanly (exit code 1) (1625 ms @ 2018/11/8 16:02:09)
这意思就是说我的仓库索引里还有之前子模块的路径呗,于是乎,我又来了一番操作:
来一次提交commit,用的tortoisegit,会提示之前的子模块路径是missing状态,提交,也就是把它从仓库索引中删除了。
这样之后再重新添加子模块,发现还是有错误:
git.exe submodule add -- "git@129.1.5.119:TerminalRD/SW/JZQ-I/modem-release.git" "components/modem"
A git directory for 'components/modem' is found locally with remote(s):
origin git@129.1.5.119:gongrl/modem_release.git
If you want to reuse this local git directory instead of cloning again from
git@129.1.5.119:TerminalRD/SW/JZQ-I/modem-release.git
use the '--force' option. If the local git directory is not the correct repo
or you are unsure what this means choose another name with the '--name' option.
git did not exit cleanly (exit code 1) (2015 ms @ 2018/11/8 16:19:38)
继续上网找,原来是之前没有删除干净,还有一步:
使用命令行工具执行命令:rm -rf .git/modules/path_to_submodule 删除.git下的缓存模块
然后再添加就ok了。











网友评论