我在本地网络(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 get
和git
的组合使用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/