如何将 go.mod 中的 Go 模块依赖指向 repo 中的最新提交? [英] How to point Go module dependency in go.mod to a latest commit in a repo?
问题描述
从 v1.11 开始,Go 添加了对模块的支持.命令
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 get' 将正确更新依赖文件(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-downgrade-dependencies
这篇关于如何将 go.mod 中的 Go 模块依赖指向 repo 中的最新提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!