GIT - 致命:无法解析主机:bitbucket.org

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

GIT - fatal: Could not resolve host: bitbucket.org

gitsshhttpsbitbucket

提问by RhysBradbury

I understand there are many Git questions like mine and I can assure you I've been scraping the web and trying all solutions, to the point where I need to post my own question.

我知道有很多像我这样的 Git 问题,我可以向你保证,我一直在搜索网络并尝试所有解决方案,以至于我需要发布我自己的问题。

General Info:
OS: Windows 7
Git Version: 1.9.0.msysgit.0
ssh version: OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007

一般信息:
操作系统:Windows 7
Git 版本:1.9.0.msysgit.0
ssh 版本:OpenSSH_4.6p1、OpenSSL 0.9.8e 2007 年 2 月 23 日

Git Error Message:

Git 错误信息:

E:\git-projects\project-psl-v3>git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

In Git 2.0, Git will default to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

ssh: bitbucket.org: no address associated with name
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

So the question:

How can I resolve this issue and push up to the remote repository?
I didn't change anything on my PC (windows update possibly?).
I can commit locally, I have the correct ssh keys in place.
I've tried cloning another repo, same error message.
I do have the correct privileges.
I've tried via https also, same error message.
I've reinstalled ssh and git, same error message.
I have also changed my dns to 4.2.2.1 and 8.8.8.8, same error message.
There is also no proxy on my internet options.

Any alternative ideas on solving this issue will be greatly appreciated.

Cheers in advance,
Rhys

所以问题是:

如何解决这个问题并推送到远程存储库?
我没有更改我的 PC 上的任何内容(可能是 Windows 更新?)。
我可以在本地提交,我有正确的 ssh 密钥。
我试过克隆另一个 repo,同样的错误消息。
我确实有正确的特权。
我也通过 https 尝试过,同样的错误消息。
我已经重新安装了 ssh 和 git,同样的错误信息。
我也将我的 dns 更改为 4.2.2.1 和 8.8.8.8,同样的错误信息。
我的互联网选项也没有代理。

任何解决此问题的替代想法将不胜感激。

提前干杯,
里斯

回答by chris polzer

I had the same message and on the commandline changed my settings to

我有同样的消息,并在命令行上将我的设置更改为

git config --global push.default current

...so it will always use my current branch as default to push.

...所以它将始终使用我当前的分支作为默认推送。

In your repository you could do a git config -lto overview the settings for your repository. This will show all settings: System-, global- and projectwide.

在您的存储库中,您可以查看存储库git config -l的设置。这将显示所有设置:系统、全局和项目范围。

Regarding SSH: Could it be possible you need to setup a ssh shortcut in your ssh-config named "bitbucket.org" so you are able to issue a ssh bitbucket.orgcommand on your commandline? I found a few examples for this searching the internet for "ssh config file"

关于 SSH:您是否可能需要在名为“bitbucket.org”的 ssh-config 中设置一个 ssh 快捷方式,以便您能够ssh bitbucket.org在命令行上发出命令?我在网上搜索“ssh 配置文件”时找到了一些示例

Check this manual for the SSH Part: https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git

查看本手册的 SSH 部分:https: //confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git

回答by John Meyer

SSH is not talking to DNS. I researched this and the forum on the Atlasssian site does not provide this or a workaround. SSH setup page is about key pairs, not DNS. RhysBlackberry's above comment works; substitute bitbucket.orgwith the IP address. The following example assumes remote is called origin. Use pingto verify connectivity and get the ip.

SSH 不与 DNS 对话。我对此进行了研究,Atlasssian 站点上的论坛未提供此信息或解决方法。SSH 设置页面是关于密钥对的,而不是 DNS。RhysBlackberry 的上述评论有效;替换bitbucket.org为 IP 地址。以下示例假定调用了 remote origin。使用ping验证连接和获取IP地址。

>ping -n 1 bitbucket.org

Pinging bitbucket.org [131.103.20.168] with 32 bytes of data:
Reply from 131.103.20.168: bytes=32 time=109ms TTL=128

>git config remote.origin.url
[email protected]:myuser/myrepo.git

To use as a workaround one time, pass a URL as the repository value with the IP instead of hostname:

要一次性用作解决方法,请使用 IP 而不是主机名传递 URL 作为存储库值:

>git push [email protected]:myuser/myrepo.git

OR, to make a config change for your local repository, update the configuration value:

或者,要对本地存储库进行配置更改,请更新配置值:

>git config remote.origin.url [email protected]:myuser/myrepo.git

Using a hardcoded IP is not best practice as bitbucket.org may change its IP.

使用硬编码 IP 不是最佳做法,因为 bitbucket.org 可能会更改其 IP。

回答by M.Fauzdar

As weird as it may sound, restarting the computer worked as I believe it was caused by abnormal shutdown of my computer.

尽管听起来很奇怪,但重新启动计算机可以正常工作,因为我认为这是由计算机异常关闭引起的。

回答by Steve Streeting

As mentioned in some of the comments here already, the contents of your SSH config file can be critical when you have this sort of problem. You can find the config file in ~/.ssh/configon Linux/Mac and at %USERPROFILE%\.ssh\configon Windows (assuming you're using OpenSSH as your client; if using PuTTY it has its own profiles which do largely the same thing, you'll see them just by starting PuTTY standalone - I won't cover that separately)

正如这里的一些评论中已经提到的,当您遇到此类问题时,您的 SSH 配置文件的内容可能至关重要。您可以~/.ssh/config在 Linux/Mac 和%USERPROFILE%\.ssh\configWindows上找到配置文件(假设您使用 OpenSSH 作为您的客户端;如果使用 PuTTY,它有自己的配置文件,这些配置文件的功能大致相同,您只需启动 PuTTY 即可看到它们独立 - 我不会单独介绍)

You need to make sure that if you have a bitbucket.orgentry in this config file, that all its directives remain correct. For example, this entry would cause a DNS problem just like you were seeing, only with SSH (ping would work fine):

你需要确保如果你bitbucket.org在这个配置文件中有一个条目,它的所有指令都保持正确。例如,这个条目会像您看到的一样导致 DNS 问题,只有使用 SSH(ping 可以正常工作):

Host bitbucket.org
    HostName bitbocket.org

Any other incorrect settings under this host can cause other issues; for example an outdated IdentityFileentry can cause key login failures even if your default key is now correct, an incorrect port entry will cause general connection timeout issues.

此主机下的任何其他不正确设置都可能导致其他问题;例如,IdentityFile即使您的默认密钥现在正确,过时的条目也可能导致密钥登录失败,错误的端口条目将导致一般连接超时问题。

Whenever you get connection or authentication problems specifically associated with ssh, and other people aren't having issues, then the most likely culprit is your ssh config file.

每当您遇到与 特定相关的连接或身份验证问题ssh,而其他人没有遇到问题时,最有可能的罪魁祸首就是您的 ssh 配置文件。