我有一个私有项目,它在github.com/company/company-product
使用一个私有模块。当我尝试构建项目时,我得到:
go: github.com/company/company-product@v1.0.4: reading github.com/company/company-product/go.mod at revision v1.0.4: unknown revision v1.0.4
我尝试过的东西:
- 已检查标记是否存在
go env -w GO111MODULE=on
go env -w GOPRIVATE=github.com/company/company-product
export GOPRIVATE=github.com/company/*
export GONOPROXY=github.com/company/*
export GONOSUMDB=github.com/company/*
- 将git配置为使用
ssh://git@github.com/
而不是https://github.com/
- 将git配置为使用
ssh://$PERSONAL_ACCESS_TOKEN@github.com/
而不是https://github.com/
- 删除
$GOPATH/pkg
中的所有内容 go clean
go mod download
、go mod tidy
、go mod vendor
(均产生上述误差(- 已重新启动我的计算机
- 已连接到我公司的VPN
但是我仍然得到同样的错误。
看起来关键是按照特定的顺序做事:
- 重新安装Go
- 将环境变量GOPRIVATE、GONOPROXY、GONOSUMDB设置为
github.com/company/*
- 删除文件夹
$GOPATH/pkg
- 将Git设置为使用
ssh://git@github.com/
而不是https://github.com/
- 运行
go get github.com/company/company-product
适用于我的解决方案;
- go env-w GOPRIVATE=github.com/company
- git-config—全局url"https://username:accesstoken@github.com";。代替";https://github.com">
- env GIT_TERMINAL_PROMPT=1访问github.com/company/privaterepo