代码之家  ›  专栏  ›  技术社区  ›  Léo Léopold Hertz 준영

无法'git子模块foreach git pull`

  •  4
  • Léo Léopold Hertz 준영  · 技术社区  · 15 年前

    这个问题是基于 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中作为子模块的外部存储库上载内容?

    3 回复  |  直到 15 年前
        1
  •  5
  •   VonC    15 年前

    这通常是在没有远程配置时发生的错误。
    (从 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中的现有信息。
    然后可以在中自定义子模块克隆URL .git/配置 对于您的本地设置,继续执行git子模块更新;您也可以使用 git submodule update --init 如果不打算自定义任何子模块位置,则不使用显式初始化步骤。

    如果远程repo(在.git/modules中声明)在.git/config中被充分引用,则不应再出现此错误消息。

    在使用(Pullin)子模块之前,步骤如下:

    git submodule init
    git submodule update
    

    保持必要。

        2
  •  1
  •   Léo Léopold Hertz 준영    15 年前

    .git/config是什么样子的? 你的箱子子模块?

    我的GIT/CONFIG

    [core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
    [remote "github"]
        url = git@github.com:masi/Sam.git
        fetch = +refs/heads/*:refs/remotes/github/*
    [submodule "bin"]
        url = git://github.com/masi/bin.git
    
        3
  •  0
  •   Léo Léopold Hertz 준영    15 年前

    我删除了.git/config中的子模块部分。

    我跑

    ~ master* $ git submodule init                      #this adds it back to .git/config
    Submodule 'bin' (git://github.com/masi/bin.git) registered for path 'bin'
    ~ master* $ git submodule update 
    ~ master* $ git submodule foreach git pull
    Entering 'bin'
    fatal: Where do you want to fetch from today?
    Stopping at 'bin'; script returned non-zero status.
    ~ master* $ 
    

    同样的问题依然存在。