go build 找不到修订版

Rav*_*ter 15 module github go

我在计算机 A 上开发了一个 repo 并创建了一个我签入的 go.mod/go.sum。

我使用计算机 B 上的 go.mod/go.sum 文件拉出该 repo,但是当我尝试构建程序时,无法满足模块约束。

$ go build
go: finding github.ibm.com/kms/key-protect-client v0.1.5
go: finding golang.org/x/tools v0.0.0-20180221164845-07fd8470d635
go: github.ibm.com/kms/key-protect-client@v0.1.5: unknown revision v0.1.5
go: error loading module requirements
Run Code Online (Sandbox Code Playgroud)

失败的 repo 是一个私有 repo,由于某种原因它没有被下载到模块缓存中。在另一台计算机上,下载依赖项并且构建成功。我正在同一个域中构建另一个私有存储库,所以我知道我的 github 凭据使我可以访问这些存储库。但是由于某种原因,go 模块系统无法访问依赖的 repo。

我找不到更多关于如何调试的信息。

igo*_*ack 27

如果您使用私有存储库,golang 未知修订的可能解决方案:

  1. git config --global url."ssh://git@yourserver".insteadOf "https://yourserver"

  2. 检查您的 git 存储库权限


小智 6

我也遇到了同样的问题,请访问链接

确保您已设置 GO111MODULES

go env -w GO111MODULE=on
Run Code Online (Sandbox Code Playgroud)

确保您的 git 配置适合私有存储库

git config --global url."ssh://git@github.com:acme-corporation".insteadOf "https://github.com/acme-corporation"
Run Code Online (Sandbox Code Playgroud)

如果使用 2FA,请确保创建个人访问令牌

git config --global url."https://:x-oauth-basic@github.com:acme-corporation".insteadOf "https://github.com/acme-corporation"
Run Code Online (Sandbox Code Playgroud)

就我而言,设置后:

  • 〜/.gitconfig
  • ~/.bashrc

我必须对 ~/.netrc 文件执行相同的操作:

machine gitlab.url.com
    login <gitlab username>
    password <GITLAB_TOKEN>
Run Code Online (Sandbox Code Playgroud)

  • 有些人(包括我)出于安全原因不鼓励使用“.netrc” - 在我看来,添加明文密码或身份验证令牌是不好的做法,只能用于确定失败的原因。这个问题还有其他解决方案 - 请参阅上面的帖子。 (3认同)

Rav*_*ter 3

问题与 cmd/go 不知道 git 身份有关,并且假设 .gitconfig 文件中只有一个。

解决方法:当您需要使用 git 身份并处理更新模块文件的 cmd/go 工具时,准备一组 git 身份来替换全局 .gitconfig。

  • 这是一个抽象的解决方案 - 您可以编写解决方法的实际步骤/命令吗? (25认同)