无法“git submodule foreach git pull”

发布于 2024-07-27 13:29:41 字数 1077 浏览 3 评论 0原文

这个问题基于此线程

我的 .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 = binpath = /Users/Masi/bin。 然而,这并不能解决问题。

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

This question is based on this thread.

My .gitmodules is at my Home

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

My folder -structure at my Home:

~
|-- [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
    ...

I run

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

I run

git submodule foreach git pull

I get

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

My first assumption to fix the bug was to change path = bin to path = /Users/Masi/bin. However, this does not solve the problem.

How can you upload the content from the external repository which is a submodule in my Git?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

末骤雨初歇 2024-08-03 13:29:41

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

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

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

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

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


因此,此消息表明 .git/modules 中提到的远程存储库未在 .git/config 中声明

git submodule

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

我相信你可能错过了git submodule init这一步:

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..update 配置变量提供自定义命令的描述。

请参阅 提交 7cebc5b(2023 年 7 月 25 日),作者:Petar Vutov (pvutov)
(由 Junio C Hamano -- gitster -- 合并于 提交 a53e8a6,2023 年 8 月 4 日)

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

签署人:Petar Vutov

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

自定义命令none选项被描述为具有相同的限制,但其中一个在.gitmodules中允许,而另一个则不允许.

重写自定义命令的描述,使其更加精确,并且让读者更容易注意到.gitmodules文件中不能使用自定义命令。

git 子模块 现在包含在其 手册页

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

然后您可以在 .git/config 中自定义子模块克隆 URL

This is normally the error made when there is no remote configured.
(From this thread)

It was a patch introduced to at least fixes the regression when running "git pull" in a repository initialized a long time ago that does not use the .git/config file to specify where my remote repositories are.

a better message would probably be something like:

No default remote is configured for your current branch, and the default remote "origin" is not configured, either.

I think the message missed being made user-friendly in earlier passes due to being inaccessible at the time.


So this message indicates the remote repo mentioned in .git/modules is not declared in .git/config

From git submodule

Submodules are not to be confused with remotes, which are meant mainly for branches of the same project;
submodules are meant for different projects you would like to make part of your source tree, while the history of the two projects still stays completely independent, and you cannot modify the contents of the submodule from within the main project.

I believe you may have missed the step of git submodule init:

submodule init

Initialize the submodules, i.e. register each submodule name and url found in .gitmodules into .git/config.
The key used in .git/config is submodule.$name.url.
This command does not alter existing information in .git/config.
You can then customize the submodule clone URLs in .git/config for your local setup and proceed to git submodule update; you can also just use git submodule update --init without the explicit init step if you do not intend to customize any submodule locations.

If your remote repo (declared in .git/modules) is adequately referenced in .git/config, you should not have this error message anymore.

Before using (pullin) submodules, the steps:

git submodule init
git submodule update

remain necessary.


Note: Git 2.42 (Q3 2023) rewrites the description of giving a custom command to the submodule.<name>.update configuration variable.

See commit 7cebc5b (25 Jul 2023) by Petar Vutov (pvutov).
(Merged by Junio C Hamano -- gitster -- in commit a53e8a6, 04 Aug 2023)

doc: highlight that .gitmodules does not support !command

Signed-off-by: Petar Vutov

Bugfix for fc01a5d ("submodule update documentation: don't repeat ourselves", 2016-12-27, Git v2.12.0-rc2 -- merge).

The custom command and none options are described as sharing the same limitations, but one is allowed in .gitmodules and the other is not.

Rewrite the description for custom commands to be more precise, and make it easier for readers to notice that custom commands cannot be used in the .gitmodules file.

git submodule now includes in its man page:

It will also copy the value of submodule.$name.update, if present in
the .gitmodules file, to .git/config, but (1) this command does not
alter existing information in .git/config, and (2) submodule.$name.update
that is set to a custom command is not copied for security reasons.

You can then customize the submodule clone URLs in .git/config

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文