如何将go.mod中的Go模块依赖项指向存储库中的最新提交? [英] How to point Go module dependency in go.mod to a latest commit in a repo?
问题描述
从v1.11开始,添加了对模块的支持.命令
Starting with v1.11 Go added support for modules. Commands
go mod init <package name>
go build
会生成go.mod
和go.sum
文件,其中包含找到的所有软件包依赖版本.
would generate go.mod
and go.sum
files that contain all found versions for the package dependencies.
如果模块没有任何版本,则使用该模块的最新提交.如果某个模块确实具有发行版,则将最新的一个作为依赖项.
If a module does not have any releases, the latest commit of that module is used. If a module does have releases, the latest one is picked as a dependency.
但是有时我需要的功能不是发布的版本,而是该版本之后的提交.如何将go.mod
设置为不指向模块的发行版,而是指向模块存储库中的特定提交?
However sometimes I would need functionality that is not in a published release yet, but from a commit made after that release. How do I set go.mod
to point not to a release of a module, but to a specific commit in the module's repository?
看起来我可以用go.mod手工完成
It looks like I can do it by hand in go.mod with
module /my/module
require (
...
github.com/someone/some_module v0.0.0-20181121201909-af044c0995fe
...
)
其中v0.0.0
与上次发布的发行标签不对应,20181121201909
是提交时间戳,而af044c0995fe
是提交哈希?应该手动找到并输入此类信息,还是有更好的方法?
where v0.0.0
does not correspond to the last published release tag, 20181121201909
would be a commit timestamp and af044c0995fe
would be the commit hash? Should such information to be found and entered by hand, or there is a better way?
推荐答案
只需转到"所需的提交哈希值即可:
Just 'go get' at the commit hash you want:
go get github.com/someone/some_module@af044c0995fe
获取"将正确更新依赖项文件(go.mod,go.sum).
'go get' will correctly update the dependency files (go.mod, go.sum).
更多信息: https://github .com/golang/go/wiki/Modules#how-to-upgrade-and-gradegrade-dependencies
这篇关于如何将go.mod中的Go模块依赖项指向存储库中的最新提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!