英文:
Why go get downloads two versions of same package when using -u
问题
我使用go get -u
命令获取一个依赖于golang.org/x/text@v0.3.7
的包。我注意到它首先下载了golang.org/x/text@v0.3.7
,然后下载了golang.org/x/text@v0.4.0
。
然后我运行了go clean -modcache
和go get golang.org/x/text
,它下载了golang.org/x/text
的v0.4.0
版本,然后再次运行go get -u entgo.io/ent
。这次go没有下载golang.org/x/text@v0.3.7
。
所以,为什么当最新版本不存在本地时,go get -u
会同时下载旧版本和最新版本?而当最新版本在本地可用时,为什么它不会下载旧版本?
英文:
I was using go get -u
to get a package which depends on golang.org/x/text@v0.3.7
. I noticed that it first downloads golang.org/x/text@v0.3.7
then downloads golang.org/x/text@v0.4.0
.
Then I ran go clean -modcache
and go get golang.org/x/text
which downloaded v0.4.0
of golang.org/x/text
and then again go get -u entgo.io/ent
. This time go didn't download golang.org/x/text@v0.3.7
So, Why go get -u
downloads both the old version and latest version when the latest version is not present locally, and Why it doesn't download the old version when the latest version is available locally?
答案1
得分: 1
因为这是一个两步骤的过程:
- 获取依赖项
- 更新依赖项
从编程的角度来看,没有将这两个步骤合并为一个"获取最新依赖项"的单一关注点的好理由。
根据go命令文档:
-u标志指示get命令更新命令行上指定的包的依赖模块,以使用较新的次要或补丁版本。
这意味着-u
特别处理的是你正在获取的包所依赖的模块,而不是你正在获取的包的模块。
此外,似乎-u
对于Go的习惯方式是不可知的,即将v0
版本的任何更改都视为主要版本更改,因此不能轻率地建议出于原则而使用-u
。甚至golang.org/x/test的README中都提到:
在达到x/text的1.0.0版本之前,次要版本被视为主要版本。因此,从0.1.0到0.2.0被认为是一个主要版本的升级。
英文:
Because it is a two-step process of
- Getting dependencies
- Updating dependencies
From a programming standpoint there is no good reason to merge these into a single concern of "Get latest dependencies".
From the go command documentation:
> The -u flag instructs get to update modules providing dependencies of packages named on the command line to use newer minor or patch releases when available.
This means that -u
specifically deals with modules which the package you are getting depends on, rather than with the module of the package you are getting.
Furthermore, it appears that -u
is agnostic to the Go idiom of treating any change in a v0
version as a major version change, so one cannot lightheartedly recommend using -u
out of principle. The README of golang.org/x/test even says:
> Until version 1.0.0 of x/text is reached, the minor version is considered a major version. So going from 0.1.0 to 0.2.0 is considered to be a major version bump.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论