无法`git submodule foreach git pull`

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1155095/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:45:43  来源:igfitidea点击:

Unable to `git submodule foreach git pull`

gitrepositorygit-submodulesgit-pull

提问by Léo Léopold Hertz ??

This question is based on this thread.

这个问题是基于这个线程

My .gitmodules is at my Home

我的 .gitmodules 在我家

[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 = binto path = /Users/Masi/bin. However, this does not solve the problem.

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

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

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

回答by VonC

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 long time ago that does not use the .git/config file to specify where my remote repositories are.

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

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

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

From git submodule

来自git 子模块

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:

我相信您可能错过了以下步骤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/configis submodule.$name.url.
This command does not alter existing information in .git/config.
You can then customize the submodule clone URLs in .git/configfor your local setup and proceed to git submodule update; you can also just use git submodule update --initwithout the explicit init step if you do not intend to customize any submodule locations.

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

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

如果你的远程仓库(在 .git/modules 中声明)在 .git/config 中被充分引用,你就不应该再有这个错误信息了。

Before using (pullin) submodules, the steps:

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

git submodule init
git submodule update

remain necessary.

保持必要。