我已经正确配置了 ssh,我可以通过 ssh 用我们的私有(private)仓库做 git 的东西。但是当我用 go get
测试时或 go test
(对于 go 模块)cli 不使用 ssh 而是使用 https。
.gitconfig
[url "ssh://git@bitbucket.company.com:7999"]
insteadOf = https://bitbucket.company.com/scm
~/.ssh/config
Host bitbucket.company.com
User git
Port 7999
IdentityFile ~/.ssh/id_rsa
测试 ssh 是否有效
$ git ls-remote ssh://git@bitbucket.company.com:7999/project/repo.git
ab86e12ab20775a308b7d0b003ba562263fbfa23 HEAD
ab86e12ab20775a308b7d0b003ba562263fbfa23 refs/heads/master
ab86e12ab20775a308b7d0b003ba562263fbfa23 refs/tags/v0.0.1
测试去获取
$ go get -v bitbucket.company.com/project/repo
go get bitbucket.company.com/project/repo: unrecognized import path "bitbucket.company.com/project/repo": https fetch: Get "https://bitbucket.company.com/project/repo?go-get=1": dial tcp 10.68.204.3:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
去版
go version go1.14.1 windows/amd64
去环境
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\sailhenz\AppData\Local\go-build
set GOENV=C:\Users\sailhenz\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=none
set GONOSUMDB=*.company.com
set GOOS=windows
set GOPATH=C:\Users\sailhenz\Documents\Development\Go
set GOPRIVATE=*.company.com
set GOPROXY=https://goproxy.io,direct
set GOROOT=C:\Users\sailhenz\Documents\Software\go
set GOSUMDB=off
set GOTMPDIR=
set GOTOOLDIR=C:\Users\sailhenz\Documents\Software\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\sail~1\AppData\Local\Temp\go-build227330694=/tmp/go-build -gno-record-gcc-switches
我错过了任何设置/配置?
提前致谢。
最佳答案
尝试:
[url "bitbucket.company.com:"]
insteadOf = https://bitbucket.company.com/
这将改变任何 https://bitbucket.company.com/
进入 bitbucket.company.com:
然后会:~/.ssh/config
)为 ssh://git@bitbucket.company.com:7999/...
关键是使用
bitbucket.company.com
单独,这是您的 ~/.ssh/config
中的主机条目文件,这意味着它将引用正确的私钥文件。subham sarkar报告 in the comments关于
golang/go
issue 27344上面提到的解决方案似乎不适用于 Go 1.13,并且在 Go 1.14 中“积压”。
检查相同的 go get 是否适用于 Go 1.11 的测试。
OP sailhenz the comments 中提及issue 27254
cmd/go
: 自定义导入路径私有(private)仓库需要特殊配置adding .git in the import path resolves it
票加了:
The reason the
.git
solution works is that it helps guide thego tool
with information about where the VCS for custom import pathsprivate.repo.net/user/package.git/...
resides (namely(https|ssh)://private.repo.net/user/package.git
).Without this (i.e. with an import path like
private.repo.net/user/package/a
), thego tool
first querieshttps://private.repo.net/user/package/a?go-get=1
to work out (according to https://tip.golang.org/cmd/go/#hdr-Remote_import_paths) where the VCS for that custom import path lives.
一个
go get -x private.repo.net/user/package
是调试这个的好方法。
关于git - 为什么 'go get' 即使配置了 ssh 也要使用 https?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61071929/