英文:
Difference between go mod download and go mod tidy
问题
go mod download
和go 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论