git子模块同步不起作用

标签 git git-submodules

我正在尝试根据 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/

相关文章:

android - Git使用Gradle必须忽略哪些文件?

git - 安装 GitWeb - 如何

在 git 子目录中执行 git init

Git 展平子模块

git - 使用 Git move 子模块

git - 在不提交的情况下将文件添加到 git index

git 只克隆一个子目录,在当前目录的根目录下

git extensions 显示多个 "branches"即使我只选择一个

git - 如何在父存储库的两次提交之间查看应用于子模块的提交?

git - 将库开发转移到自己的项目中