无法`git submodule foreach git pull`

问题描述 投票:0回答:1

这个问题基于这个帖子

我的 .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 中的子模块外部存储库上传内容?

git repository git-submodules git-pull
1个回答
5
投票

这通常是没有配置远程时发生的错误。
(来自此线程

这是一个补丁,至少可以修复在很久以前初始化的存储库中运行“git pull”时的回归问题,该存储库不使用

.git/config
文件来指定我的远程存储库所在的位置。

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

当前分支没有配置默认远程,也没有配置默认远程“origin”。

我认为由于当时无法访问该消息,因此在早期版本中未能使该消息变得用户友好。


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

来自 git 子模块

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

我相信你可能错过了

git submodule init
的步骤:

子模块初始化

初始化子模块,即将 .gitmodules 中找到的每个子模块名称和 url 注册到 .git/config

.git/config
中使用的键是
submodule.$name.url

此命令不会更改 .git/config 中的现有信息。
然后,您可以在
.git/config
中自定义子模块克隆 URL 以进行本地设置,然后继续进行
git submodule update
;如果您不打算自定义任何子模块位置,您也可以只使用
git submodule update --init
而无需显式初始化步骤。

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

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

git submodule init
git submodule update

仍然有必要。


注意:Git 2.42(2023 年第 3 季度)重写了向

submodule.<name>.update
配置变量提供自定义命令的描述。

请参阅commit 7cebc5b(2023 年 7 月 25 日),作者:Petar Vutov (

pvutov
)
(由 Junio C Hamano --
gitster
--
合并于 commit a53e8a6,2023 年 8 月 4 日)

doc
:突出显示
.gitmodules
不支持
!command

签署人:Petar Vutov

fc01a5d的错误修复(“子模块更新文档:不要重复自己”,2016-12-27,Git v2.12.0-rc2 - merge)。

custom command
none
选项被描述为具有相同的限制,但其中一个在
.gitmodules
中允许,而另一个则不允许。

重写自定义命令的描述,使其更加精确,并且让读者更容易注意到自定义命令不能在

.gitmodules
文件中使用。

git submodule
现在包含在其 手册页中:

它还会复制

submodule.$name.update
的值(如果存在于
.gitmodules
文件,到
.git/config
,但是 (1) 该命令不 更改
.git/config
中的现有信息,以及 (2)
submodule.$name.update
出于安全原因,设置为自定义命令的内容不会被复制。

然后您可以在

.git/config

中自定义子模块克隆 URL
© www.soinside.com 2019 - 2024. All rights reserved.