我正在尝试根据 these instructions 更改子模块上的 Remote .
修改保存后.gitmodules
, 然后做 git submodule sync
我的子模块没有改变,尽管我的 .git/config
文件已更新以匹配 .gitmodules
中的新远程 URL .
我也试过 git submodule sync --recursive
,并做 rm -rf .git/modules/<mySubmodule>
根据 this tip没有任何区别。事实上,然后运行后一个命令 git submodule sync
再次给出 fatal: Not a git repository: ../.git/modules/<mySubmodule>
.有什么建议吗?
我最初通过 git submodule add git://<mySubmodule-url>
将子模块添加到项目中根据 git docs .
编辑
我什至通过自制软件将 git 更新到 v2.1.1,但仍然没有。我也尝试过完全从头开始,甚至在两个完全不同的子模块之间切换,但我仍然得到相同的结果。总结:
$> mkdir myRepo
$> cd myRepo
myRepo$> git init .
myRepo$> git submodule add https://<path/to/my/repo>.git
myRepo$> vim .gitmodules
# change submodule url to https://<path/to/another/repo>.git
myRepo$> git submodule sync # updates my .git/config file with the new submodule url, but all my files in the submodule are still from the old url
myRepo$> git submodule sync --recursive # doesn't do anything
myRepo$> git submodule update --init --recursive # doesn't do anything either
myRepo$> rm -rf .git/modules/<mySubmodule> # tip from SO comment linked above
myRepo$> git submodule sync
fatal: Not a git repository: ../.git/modules/<mySubmodule>
最佳答案
这看起来确实很烦人。不理想,但以下似乎对我有用
git submodule foreach git pull --rebase
关于git子模块同步不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26108137/