jos*_*ine 87 git git-submodules
如何用不同的git repo替换git子模块?
具体来说,我有一个子模块:
./ExternalFrameworks/TestFramework那个点到git repogit@github.com:userA/TestFramework.git git@github.com:userB/TestFramework.git.问题是当我用这里描述的方法删除子模块时,然后使用该命令重新添加它
git submodule add git@github.com:userB/TestFramework.git
我收到此错误:
A git directory for 'ExternalFrameworks/TestFramework' is found locally with remote(s):
  origin    git@github.com:userA/TestFramework.git
If you want to reuse this local git directory instead of cloning again from
  git@github.com:userB/TestFramework.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.
Tim*_*gan 112
如果子模块的位置(URL)已更改,那么您可以简单地:
.gitmodule文件以使用新URLrm -rf .git/modules/<submodule>更完整的信息可以在其他地方找到:
jos*_*ine 32
首先,使用此处已提到的方法删除当前子模块,为方便起见,我将其包括在内:
.gitmodules文件中删除相关部分.git/configgit rm --cached path_to_submodule(没有斜杠)现在,添加带有--name标志的新子模块.这将为git提供一个替代名称来引用.git/config子模块,与历史上存在的子模块冲突,您仍然希望在之前的历史记录中工作.
所以输入:
git submodule add --name UpdatedTestFramework git@github.com:userB/TestFramework.git
并且你将在你期望的路径上加载子模块.
这些命令将在命令提示符下完成工作,而不会更改本地存储库上的任何文件.
git config --file=.gitmodules submodule.Submod.url https://github.com/username/ABC.git
git config --file=.gitmodules submodule.Submod.branch Dev
git submodule sync
git submodule update --init --recursive --remote
为我修复此问题的原因是你的git repo(不是子模块)的根目录,运行
rm -rf .git/modules/yourmodule
然后你应该能够正常添加.