git - go get无法使用不可路由的IP地址

标签 git go go-get

我在本地网络(192.168.0.12)的计算机上安装了git repo。它在/etc/hosts中有一个条目

192.168.0.12    ubuntu-18-extssd
go get无法将我的主机名(ubuntu-18-extssd)识别为主机名,因此我改用IP地址。
现在当我尝试去得到这样
go get 192.168.0.12/gitrepo/go-package-test-stringutil/stringpackage
它返回错误
package 192.168.0.12/gitrepo/go-package-test-stringutil/stringpackage: unrecognized import path "192.168.0.12/gitrepo/go-package-test-stringutil/stringpackage": https fetch: Get "https://192.168.0.12/gitrepo/go-package-test-stringutil/stringpackage?go-get=1": dial tcp 192.168.0.12:443: connect: connection refused
所以我告诉git使用ssh代替:
git config --global url."dean@192.168.0.12:".insteadOf "https://192.168.0.12/"
在我的〜/.gitconfig中
[url "git@github.com:"]
    insteadOf = https://github.com/
[url "dean@192.168.0.12:"]
    insteadOf = https://192.168.0.12/
但是去获取仍然会给出同样的错误。 github的条目有效。
为什么当我告诉go getgit的组合使用ssh时仍尝试使用https?

最佳答案

Go无法直接从192.168.0.12/gitrepo/go-package-test-stringutil/stringpackage推断存储库类型,因此它正在尝试在https://192.168.0.12/gitrepo/go-package-test-stringutil/stringpackage?go-get=1上查找元标记:

If the import path is not a known code hosting site and also lacks a version control qualifier, the go tool attempts to fetch the import over https/http and looks for a tag in the document's HTML .


https://golang.org/cmd/go/#hdr-Remote_import_paths
如果您不想运行返回相应元标记的服务器,则必须通过将.git添加到导入路径来让Go知道该软件包在git存储库中。根据存储库所在的位置,使用以下命令之一:
go get 192.168.0.12/gitrepo/go-package-test-stringutil/stringpackage.git
go get 192.168.0.12/gitrepo/go-package-test-stringutil.git/stringpackage
go get 192.168.0.12/gitrepo.git/go-package-test-stringutil/stringpackage

关于git - go get无法使用不可路由的IP地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63784938/

相关文章:

git - 是否可以 merge 从同一 CVS 源导入的不相交的 Git 存储库?

go - 如何通过 Golang 中的短变量声明将返回值分配给函数输入?

go - 为什么systemd无法启动golang web app,没有答案

git - 在公司防火墙后面如何让 go get 为 golang.org 工作

Go get 拉错了仓库

去获取私有(private) bitbucket repo,禁止 403

ios - Xcode CI 和 cocoapods 私有(private)仓库

git - 如何使 git difftool 始终导出绝对路径

git - 是否可以跳过暂存区并(也)将未跟踪的新文件提交给 git?

mongodb - 将 MongoDB 函数 foreach 转换为 mgo (Golang) 函数