【问题标题】:git submodule sync doesn't workgit子模块同步不起作用
【发布时间】:2014-09-29 20:18:12
【问题描述】:

我正在尝试按照these instructions 更改子模块上的遥控器。

修改并保存.gitmodules,然后执行git submodule sync,我的子模块并没有改变,尽管我的.git/config文件已经更新以匹配.gitmodules中的新远程url。

我也试过git submodule sync --recursive,并按照this tiprm -rf .git/modules/<mySubmodule>,没有任何区别。事实上,运行后一个命令然后git submodule sync 再次给出fatal: Not a git repository: ../.git/modules/<mySubmodule>。有什么建议吗?

我最初按照git docs 将子模块通过git submodule add git://<mySubmodule-url> 添加到项目中。

编辑

我什至通过 homebrew 将 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 update --init --recursive 行不通(在git submodule sync --recursive 之后)?
  • 不——我仍然看到原来的子模块。

标签: git git-submodules


【解决方案1】:

这似乎很烦人。不理想,但以下似乎对我有用

git submodule foreach git pull --rebase

【讨论】:

  • 是的,成功了!绝对不理想,但我会接受。在我接受之前你能解释一下你的答案吗?另外,你能复制我的问题吗?
  • 我确实看到 Git 2.1.1 的行为相同。老实说,我不确定这是“预期”还是错误。子模块总是有些做作。至于它为什么起作用 - 它会导致 git 进入子模块并进行提取(在我的情况下,它再次转换为强制分支 - 再次,不知道为什么)。
  • @IgorGanapolsky-您可能想提出一个新问题并提供更多详细信息。问候
猜你喜欢
  • 1970-01-01
  • 2014-08-29
  • 1970-01-01
  • 2014-03-04
  • 2022-01-13
  • 2011-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多