为什么 git fetch 失败并显示“无法解析主机:(nil)...”与 https://github.com/mxcl/homebrew 来源?

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

Why does git fetch fail with "Could not resolve host: (nil)..." with https://github.com/mxcl/homebrew origin?

gitgithubhttps

提问by Daryl Spitzer

I was unable to install Homebrew(see my question on apple.stackexchange.com), so I looked at the https://raw.github.com/mxcl/homebrew/goRuby script and tried the same commands it runs:

我无法安装Homebrew(请参阅我在 apple.stackexchange.com 上的问题),所以我查看了https://raw.github.com/mxcl/homebrew/goRuby 脚本并尝试了它运行的相同命令:

$ git init -q
$ git remote add origin https://github.com/mxcl/homebrew
$ git fetch origin master:refs/remotes/origin/master -n
error: Could not resolve host: (nil); nodename nor servname provided, or not known while accessing https://github.com/mxcl/homebrew/info/refs?service=git-upload-pack
fatal: HTTP request failed

Why am I getting this error?

为什么我收到这个错误?

Update:(in response to madhead's answer)

更新:(回应madhead的回答)

I get the same problem when I use the URL with .gitpostfixed:

当我使用带有.git后缀的 URL 时,我遇到了同样的问题:

$ git init -q
$ git remote add origin https://github.com/mxcl/homebrew.git
$ git fetch origin master:refs/remotes/origin/master -n
error: Could not resolve host: (nil); nodename nor servname provided, or not known while accessing https://github.com/mxcl/homebrew.git/info/refs?service=git-upload-pack
fatal: HTTP request failed

Update #2:

更新#2:

I don't think this was a proxy issue (as suggested in neil'sanswer).

我不认为这是代理问题(正如尼尔的回答中所建议的那样)。

I tried this again and it worked!

我又试了一次,它奏效了!

$ git init -q
$ git remote add origin https://github.com/mxcl/homebrew
$ git fetch origin master:refs/remotes/origin/master -n
remote: Counting objects: 126721, done.
remote: Compressing objects: 100% (59085/59085), done.
remote: Total 126721 (delta 89963), reused 100145 (delta 66623)
Receiving objects: 100% (126721/126721), 19.68 MiB | 702 KiB/s, done.
Resolving deltas: 100% (89963/89963), done.
From https://github.com/mxcl/homebrew
 * [new branch]      master     -> origin/master

I looked in my ~/.gitconfigfile and discovered I had already defined a proxy. I think that was already there when I had the problem, but to confirm I removed it and got a different error:

我查看了我的~/.gitconfig文件,发现我已经定义了一个代理。我认为当我遇到问题时它已经存在了,但是为了确认我删除了它并得到了一个不同的错误:

$ git fetch origin master:refs/remotes/origin/master -n
error: Failed connect to github.com:443; Connection refused while accessing https://github.com/mxcl/homebrew/info/refs?service=git-upload-pack
fatal: HTTP request failed

My theory is that github or homebrew had some kind of problem that they've since fixed.

我的理论是 github 或 homebrew 有一些他们已经修复的问题。

采纳答案by Neil

For me this was related to a proxy issue. When I'm on VPN I need to add

对我来说,这与代理问题有关。当我使用 VPN 时,我需要添加

[http]
proxy = http://proxy.example.com

to my ~/.gitconfig, and if I'm not on the VPN, this proxy cannot be found.

到我的~/.gitconfig,如果我不在 VPN 上,则无法找到此代理。

回答by user63497

For those getting this error when NOT behind a proxy:

对于那些不在代理后面时收到此错误的人:

error: Could not resolve host: (nil); nodename nor servname provided, or not known while accessing https://github.com/mxcl/homebrew/info/refs?service=git-upload-pack
fatal: HTTP request failed

the solution may be to clear the git proxy settings:

解决方案可能是清除 git 代理设置:

$ git config --global --unset core.gitproxy

回答by madhead

You remote URL is incorrect, it should be https://github.com/mxcl/homebrew.git(.gitpostfixed) instead of https://github.com/mxcl/homebrew. You can copypaste URLs from Github UI to prevent such typos.

您的远程 URL 不正确,它应该是https://github.com/mxcl/homebrew.git( .gitpostfixed) 而不是https://github.com/mxcl/homebrew. 您可以从 Github UI 复制粘贴 URL 以防止此类拼写错误。