如何用另一个回购replace一个git子模块?
我怎样用一个不同的git仓库replace一个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. 
	
如果子模块的位置(URL)已更改,则可以简单地:
-  修改.gitmodule文件以使用新的URL
-  运行git submodule sync
更完整的信息可以在其他地方find:
- 更改git子模块的远程存储库
- 如何改变一个git子模块的URL
首先,用这里已经提到的方法删除当前的子模块,为方便起见,
-  从.gitmodules文件中删除相关的部分
-  从.git/config删除相关部分
-  运行git rm --cached path_to_submodule(没有结尾的斜杠)
- 提交并删除现在未跟踪的子模块文件
 现在,添加带有--name标志的新子模块。 这会给git一个备用名称,以便在子模块的.git/config引用,以便与历史上存在的子模块冲突,您仍然希望在之前的历史logging中使用该子模块。 
所以input:
 git submodule add --name UpdatedTestFramework git@github.com:userB/TestFramework.git 
你会得到你所期望的path加载子模块。
这些命令将在命令提示符下执行,而不会更改本地存储库上的任何文件。
 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回购(而不是子模块)的根,运行
 rm -rf .git/modules/yourmodule 
那么你应该可以正常添加。
我发现的最简单的方法是这样的:
 git rm -rf [submodule_dir] git submodule add --name new_[submodule_name] [new_submodule_url] [submodule_dir] 
 我不喜欢这个想法手动修改我的.gitmodules 。 我也写了一个关于它的小博客 。 
如果您只想为此克隆更改远程URL:
 git config submodule."$submodule_name".url "$new_url" 
 这不会影响父项目中的.gitmodules文件,因此不会传播给其他开发人员。 
这在这里被描述为“用户特定logging改变”。
  不要运行git submodule sync因为它会重新设置为默认的URL。