git - 无法安装私有(private) Go 模块

标签 git go go-modules

我有一个私有(private)项目,它使用私有(private)模块 github.com/company/company-product 。当我尝试构建项目时,我得到:

go: github.com/company/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="22414d4f52434c5b0f52504d465741566254130c120c16" rel="noreferrer noopener nofollow">[email protected]</a>: 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://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e7808e93a7808e938f9285c984888a" rel="noreferrer noopener nofollow">[email protected]</a>/而不是https://github.com/
  • 配置 git 使用 ssh://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4064100512130f0e010c1f0103030513131f140f0b050e002729342835226e232f2d" rel="noreferrer noopener nofollow">[email protected]</a>/而不是https://github.com/
  • 删除了 $GOPATH/pkg 中的所有内容
  • go clean
  • go mod download , go mod tidy , go mod vendor (都会产生上述错误)
  • 重新启动了我的计算机
  • 已连接到我公司的 VPN

但我仍然遇到同样的错误。

最佳答案

看起来关键是按照一定的顺序做事:

  1. 重新安装 Go
  2. 将环境变量 GOPRIVATE、GONOPROXY、GONOSUMDB 设置为 github.com/company/*
  3. 删除文件夹 $GOPATH/pkg
  4. 设置要使用的 Git ssh://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a6c1cfd2e6c1cfd2ced3c488c5c9cb" rel="noreferrer noopener nofollow">[email protected]</a>/而不是https://github.com/
  5. 运行go get github.com/company/company-product

关于git - 无法安装私有(private) Go 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70341047/

相关文章:

postgresql - Golang GORM 中列的自动迁移问题

semantic-versioning - 戈朗 : separate versioning of multiple modules

git - 如何从 git log 输出中获取特定的 SHA

git - 在 Git 中,如何 rebase + 压缩历史记录中具有多个 merge 提交的分支,而不选择一个全新的分支

git - TFS Git 项目中的依赖项目 VNEXT 构建

random - 在 Go 中生成范围内的随机数

go - golang 中的工厂方法存在循环依赖问题

go - 具有多个模块的 mono-repos 中是否有 Go 模块名称的约定?

go - Golang Go使用错误的URL @ Go 1.13使用git ls-remote -q失败

linux - 如何防止交互式ssh登录?