为什么使用”go get”命令会失败并显示”无效版本:未知修订”的错误?

huangapple go评论111阅读模式
英文:

Why does go get fail with "invalid version: unknown revision"?

问题

我发布了一个更新的 Go 模块,将版本升级到 v1.1.0。我创建了一个名为 v1.1.0 的标签,并将标签推送到 GitHub。

https://github.com/depp/bytesize/releases/tag/v1.1.0

然而,我无法在我的其他项目中使用这个包。我收到一个错误,提示“无效的版本:未知的修订版本 v1.1.0”。我不知道为什么修订版本是“未知的”,因为它已经被标记了。

$ go get github.com/depp/bytesize@v1.1.0                    
go: 正在下载 github.com/depp/bytesize v1.1.0
go get github.com/depp/bytesize@v1.1.0: github.com/depp/bytesize@v1.1.0: 验证模块: github.com/depp/bytesize@v1.1.0: 读取 https://sum.golang.org/lookup/github.com/depp/bytesize@v1.1.0: 410 Gone
	server response: not found: github.com/depp/bytesize@v1.1.0: invalid version: unknown revision v1.1.0
[Exit: 1]
英文:

I published an update to a Go module, bumping the version to v1.1.0. I created a tag named v1.1.0 and pushed the tag to GitHub.

https://github.com/depp/bytesize/releases/tag/v1.1.0

However, I cannot use this package in my other projects. I get an error that says, "invalid version: unknown revision v1.1.0". I don't know why the revision is "unknown", since it's tagged.

$ go get github.com/depp/bytesize@v1.1.0                    
go: downloading github.com/depp/bytesize v1.1.0
go get github.com/depp/bytesize@v1.1.0: github.com/depp/bytesize@v1.1.0: verifying module: github.com/depp/bytesize@v1.1.0: reading https://sum.golang.org/lookup/github.com/depp/bytesize@v1.1.0: 410 Gone
	server response: not found: github.com/depp/bytesize@v1.1.0: invalid version: unknown revision v1.1.0
[Exit: 1]

答案1

得分: 23

标签在调用go get一次后被推送,这导致了Go模块代理缓存的污染。

来自https://proxy.golang.org/:

> 请注意,如果在推送标签之前有人请求了该版本,可能需要最多30分钟才能使镜像的缓存过期,并提供关于该版本的新数据。

在缓存过期之前解决此问题的方法是使用GOPRIVATE环境变量指示go get直接获取此模块,绕过缓存。

来自https://golang.org/cmd/go/:

> GOPRIVATE,GONOPROXY,GONOSUMDB
>
> 逗号分隔的模块路径前缀的通配符模式列表(使用Go的path.Match语法)
> 应始终直接获取或不应与校验和数据库进行比较。

解决方法如下:

$ GOPRIVATE=github.com/depp/bytesize go get github.com/depp/bytesize@v1.1.0

请注意,如果您已经在使用GOPRIVATE,您将希望添加模块而不是完全覆盖该值。

英文:

The tag was pushed after invoking go get once, which poisoned the Go module proxy cache.

From https://proxy.golang.org/:

> Note that if someone requested the version before the tag was pushed, it may take up to 30 minutes for the mirror's cache to expire and fresh data about the version to become available.

The way to work around this before the cache expires is to use the GOPRIVATE environment variable to instruct go get to fetch this module directly, bypassing the cache.

From https://golang.org/cmd/go/:

> GOPRIVATE, GONOPROXY, GONOSUMDB
>
> Comma-separated list of glob patterns (in the syntax of Go's path.Match)
> of module path prefixes that should always be fetched directly
> or that should not be compared against the checksum database.

The workaround is:

$ GOPRIVATE=github.com/depp/bytesize go get github.com/depp/bytesize@v1.1.0

Note that if you are already using GOPRIVATE, you will want to add modules rather than overriding the value completely.

答案2

得分: 4

尝试使用以下命令进行设置:

export GOSUMDB=off

对于出现以下错误的情况,这个方法对我有效:

验证模块:无效的GOSUMDB:验证器ID格式错误
英文:

Try with:

export GOSUMDB=off

It also works for me for the error:

verifying module: invalid GOSUMDB: malformed verifier id

答案3

得分: 0

最好是凭经验的证据,但是直接更新go.mod文件并运行go mod tidy对我有效,而其他答案都没有效果。

➜  cli git:(main) ✗ go get github.com/opencamp-hq/core@0.2.3
go: github.com/opencamp-hq/core@0.2.3: 无效的版本: 未知修订版本0.2.3
➜  cli git:(main) ✗ GOPRIVATE=github.com/opencamp-hq/core go get github.com/opencamp-hq/core@0.2.3
go: github.com/opencamp-hq/core@0.2.3: 无效的版本: 未知修订版本0.2.3
➜  cli git:(main) ✗ GOSUMDB=off go get github.com/opencamp-hq/core@0.2.3 
go: github.com/opencamp-hq/core@0.2.3: 无效的版本: 未知修订版本0.2.3

... 编辑了go.mod文件 ...
➜  cli git:(main) ✗ go mod tidy
go: 正在下载 github.com/opencamp-hq/core v0.2.3
英文:

Anecdotal evidence at best, but updating the go.mod file directly and running go mod tidy worked for me when none of the other answers did.

➜  cli git:(main) ✗ go get github.com/opencamp-hq/core@0.2.3
go: github.com/opencamp-hq/core@0.2.3: invalid version: unknown revision 0.2.3
➜  cli git:(main) ✗ GOPRIVATE=github.com/opencamp-hq/core go get github.com/opencamp-hq/core@0.2.3
go: github.com/opencamp-hq/core@0.2.3: invalid version: unknown revision 0.2.3
➜  cli git:(main) ✗ GOSUMDB=off go get github.com/opencamp-hq/core@0.2.3 
go: github.com/opencamp-hq/core@0.2.3: invalid version: unknown revision 0.2.3

... edited go.mod ...
➜  cli git:(main) ✗ go mod tidy
go: downloading github.com/opencamp-hq/core v0.2.3

huangapple
  • 本文由 发表于 2021年5月25日 03:53:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/67678203.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定