go mod download和go mod tidy之间的区别是什么?

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

Difference between go mod download and go mod tidy

问题

go mod downloadgo mod tidy之间有什么区别?

当我运行go mod tidy时,如果找不到导入的包,它也会下载它。

英文:

What is the different between go mod download and go mod tidy?

When I run go mod tidy, if the import is not found it also downloads it.

答案1

得分: 28

go mod download 是下载依赖图中的所有模块,它可以通过读取 go.mod 文件来确定。它不知道哪些模块实际上是构建所需的,因此它不会拉取这些模块的校验和(因为它们可能不相关)。

另一方面,go mod tidy 必须遍历包图以确保满足所有导入。因此,它可以确定,不需要额外工作,它遍历的模块在某种配置下是构建所需的。

英文:

go mod download
is downloading all of the modules in the dependency graph, which it can determine from reading only the go.mod files. It doesn't know which of those modules are actually needed to satisfy a build, so it doesn't pull in the checksums for those modules (because they may not be relevant).

On the other hand, go mod tidy has to walk the package graph in order to ensure that all imports are satisfied. So it knows, for a fact, without doing any extra work, that the modules it walks through are needed for a go build in some configuration.

huangapple
  • 本文由 发表于 2022年3月16日 18:41:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/71495619.html
匿名

发表评论

匿名网友

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

确定