去更新所有模块 [英] Go update all modules
问题描述
以这个模块为例(使用特定的提交,以便其他人看到我所看到的):
Using this module as an example (using a specific commit so others will see what I see):
git clone git://github.com/walles/moar
Set-Location moar
git checkout d24acdbf
我想要一种方法来告诉 Go更新所有内容".假设模块将使用最新版本的所有内容.以下是我发现的五种方法这样做,假设每个都在一个干净的克隆上运行.这导致 go.mod
为 19行:
I would like a way to tell Go to "update everything". Assume that the module
will work with the newest version of everything. Below are five ways I found to
do this, assume each is run on a clean clone. This results in a go.mod
of 19
lines:
go get -u
这导致 go.mod
有 14 行:
This results in a go.mod
of 14 lines:
go get -u
go mod tidy
这导致 go.mod
有 13 行:
This results in a go.mod
of 13 lines:
go mod tidy
如果我只是手动删除 require
中的所有内容并运行 go mod tidy
,我会得到12 行.如果我只是手动删除 require
中的所有内容并运行 go get -u
,我会得到 11 行.我的问题是,为什么这些方法会产生不同的结果,什么是正确的方法"?做我想做的事?
If I just manually delete everything in require
and run go mod tidy
, I get
12 lines. If I just manually delete everything in require
and run go get -u
, I get 11 lines. My question is, why are these methods producing different
results, and what is the "right way" to do what I am trying to do?
推荐答案
tl;dr;
这就是你想要的:
go get -u
go mod tidy
您看到的不一致是由于软件固有的有机性质造成的.
The inconsistencies you are seeing is due to the inherent organic nature of software.
使用您的示例,提交 git://github.com/walles/moar
的提交 d24acdbf
很可能是由维护人员在未运行 go mod 的情况下签入的整洁
(解释较长的 19 行).如果维护者有,那么你会看到最后看到的 13 行版本.
Using your example, commit d24acdbf
of git://github.com/walles/moar
most likely was checked in by the maintainer without running go mod tidy
(explaining the longer 19 lines). If the maintainer had, then you would see the 13 line version you see at the end.
go get -u
本身在引入依赖项方面更具侵略性.此外,仅将依赖项更新到其最新(兼容)版本的事实可能在 &本身会引入新的直接/间接依赖项.如果您明天尝试这样做,这些依赖项可能会进一步增长(某些子依赖项的最新版本添加了新功能,因此它需要新的依赖项).因此,repo 维护者修复特定(非最新)版本可能是有正当理由的.
go get -u
on it's own is more aggressive in pulling in dependencies. Also, the mere fact of updating dependencies to their latest (compatible) version, may in & of itself pull in new direct/indirect dependencies. These dependencies may grow even further if you tried this tomorrow (the latest version of some sub-dependency adds new functionality, so it needs new dependencies). So there may be a valid reason the repo maintainer fixes at a particular (non-latest) version.
go mod tidy 清理了这种激进的依赖分析.
go mod tidy cleans up this aggressive dependency analysis.
附:一个常见的误解是在 go mod tidy
之后依赖项会缩小:跟踪 go.sum
,在某些情况下这个文件会在 tidy
之后增长(不过,在这种情况下不是)
P.S. It's a common misconception that dependencies will shrink after go mod tidy
: tracking go.sum
, in some cases this file will grow after a tidy
(though, not in this case)
这篇关于去更新所有模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!