为什么 git 子模块更新失败?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7656491/
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 06:03:14  来源:igfitidea点击:

Why is git submodule update failing?

gitgit-submodules

提问by Octaflop

I have the following .gitmodulesfile:

我有以下 .gitmodules文件:

[submodule "web/blog"]
    path = web/blog
    url = git://amygdala.servebeer.com:lucky_blog.git

[submodule "web/old"]
    path = web/old
    url = git://amygdala.servebeer.com:old_lucky.git

When I clone the repo and run git submodule init && git submodule update(or git submodule init --update) I get the following error:

当我克隆 repo 并运行git submodule init && git submodule update(或git submodule init --update)时,出现以下错误:

Cloning into web/blog...
fatal: Unable to look up  (port 9418) (Name or service not known)
Clone of 'git://amygdala.servebeer.com:lucky_blog.git' into submodule path 'web/blog' failed

I observe three things which cause some concern:

我观察到三件事引起了一些关注:

  1. The second .gitmodulesentry (web/old) is cloned just fine, with no issues.
  2. There appears to be an extra space in the error message, where I think git would normally list the hostname it fails to look up (right before the port number listing in the error listed above).
  3. git clone git://amygdala.servebeer.com:lucky_blog.gitworks just fine.
  1. 第二个.gitmodules条目(网络/旧)克隆得很好,没有问题。
  2. 错误消息中似乎有一个额外的空格,我认为 git 通常会列出它无法查找的主机名(就在上面列出的错误中列出的端口号之前)。
  3. git clone git://amygdala.servebeer.com:lucky_blog.git工作得很好。

What is wrong with this repo? Is this an error with git or did I screw something up when setting up the repo?

这个回购有什么问题?这是 git 的错误还是我在设置 repo 时搞砸了什么?

EditHere's my git config for reference:

编辑这是我的 git 配置以供参考:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = [email protected]:luckybead.git
[branch "master"]
    remote = origin
    merge = refs/heads/master
[submodule "web/blog"]
    url = git://amygdala.servebeer.com:lucky_blog.git
[submodule "web/old"]
    url = git://amygdala.servebeer.com:old_lucky.git

回答by Mark Longair

You have the format of your git URLsslightly wrong - you should separate the host from the path with /rather than :. Try changing the URLs to:

的 git URL 格式略有错误 - 您应该将主机与路径分开,/而不是:. 尝试将 URL 更改为:

git://amygdala.servebeer.com/lucky_blog.git
git://amygdala.servebeer.com/old_lucky.git

You will not only need to commit those changes to .gitmodules, but also change the config with:

您不仅需要将这些更改提交到.gitmodules,还需要使用以下内容更改配置:

$ git config submodule.web/blog.url git://amygdala.servebeer.com/lucky_blog.git
$ git config submodule.web/old.url git://amygdala.servebeer.com/old_blog.git

... and to make sure that the submodules are re-cloned, remove them and try the git submodule updateagain.

...并确保子模块被重新克隆,删除它们并重试git submodule update