【问题标题】:Unable to `git submodule foreach git pull`无法`git submodule foreach git pull`
【发布时间】:2010-11-12 09:49:52
【问题描述】:

本题基于this thread

我的 .gitmodules 在我家

[submodule "bin"]
           path = bin
           url = git://github.com/masi/bin.git

我家的文件夹结构:

~
|-- [drwxr-xr-x] bin          // this is the folder which I make a submodule
                              // it is also a folder where I have a Git to push my submodule's files
    | -- fileA
    ` -- folderA
    ...

我跑

git submodule init    # I get no output from these commands
git submodule update          

我跑

git submodule foreach git pull

我明白了

Entering 'bin'
fatal: Where do you want to fetch from today?
Stopping at 'bin'; script returned non-zero status.

我修复错误的第一个假设是将path = bin 更改为path = /Users/Masi/bin。但是,这并不能解决问题。

如何从我的 Git 中的子模块外部存储库上传内容?

【问题讨论】:

  • 你的 bin 子模块的 .git/config 是什么样的?
  • @Charles:我的 .git/config 位于 stackoverflow.com/questions/1155095/…
  • 看起来你的 bin 子模块是递归的??
  • @为什么你认为bin子模块是递归的?
  • 如果您的 bin 子模块的 .git/config 文件还包含 [submodule "bin"] 部分,则该子模块可能是递归的(即,它包含自身作为子模块)。这可能会导致很多混乱。

标签: git repository git-submodules git-pull


【解决方案1】:

这通常是没有配置远程时出现的错误。
(来自this thread

这是一个补丁,至少修复了在很久以前初始化的存储库中运行“git pull”时的回归,它不使用 .git/config 文件来指定我的远程存储库的位置。

更好的信息可能是这样的:

没有为您当前的分支配置默认远程,
并且默认的远程“来源”也没有配置。

我认为该消息错过了在较早的通行证中变得易于使用的原因 到当时无法访问。


所以这个消息表明 .git/modules 中提到的远程 repo 没有在 .git/config 中声明

来自git submodule

不要将子模块与远程混淆,后者主要用于同一项目的分支;
子模块适用于您希望成为源代码树一部分的不同项目,而这两个项目的历史仍然完全独立,您无法从主项目中修改子模块的内容。

相信你可能错过了git submodule init的步骤:

子模块初始化

初始化子模块,即将 .gitmodules 中的每个子模块名称和 url 注册到 .git/config 中
.git/config 中使用的密钥是 submodule.$name.url
此命令不会更改 .git/config 中的现有信息。
然后,您可以为您的本地设置自定义 .git/config 中的子模块克隆 URL,并继续进行 git 子模块更新;如果您不打算自定义任何子模块位置,也可以只使用 git submodule update --init 而无需显式初始化步骤。

如果您的远程仓库(在 .git/modules 中声明)在 .git/config 中被充分引用,则您不应再收到此错误消息。

在使用(pullin)子模块之前,步骤:

git submodule init
git submodule update

仍然是必要的。

【讨论】:

  • 我执行了这些步骤 - 我澄清了我的问题。
  • 也就是说,命令也会出现同样的问题。
  • 好点。我遇到了类似的问题,结果我不小心在我的一个子模块中将远程 repo 从 origin 重命名为 upstream。将 repo 名称更正为 origin,然后 Git 会给出一些更实用的建议——如果你想为这个分支设置跟踪信息,你可以这样做:“git branch --set-upstream master origin/”。跨度>
猜你喜欢
  • 2023-02-26
  • 2013-11-06
  • 2018-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-25
  • 2021-11-17
  • 2020-10-19
相关资源
最近更新 更多