Home  >  Article  >  Backend Development  >  Will "go mod tidy" automatically upgrade the go version in go.mod?

Will "go mod tidy" automatically upgrade the go version in go.mod?

王林
王林forward
2024-02-06 09:05:04706browse

“go mod tidy”会自动升级go.mod中的go版本吗?

Question content

Previously this project was using go 1.20 in go.mod. I have upgraded my go version to 1.21.0 on my local Linux machine.

When I ran go mod tidy for the project, it automatically upgraded go.mod to use go 1.21.0.

If this is expected behavior, is there a way to disable this behavior, aka. When running go mod tidy, won't the go version in go.mod be automatically updated? Because others may not have upgraded locally yet.


Correct Answer


The go mod tidy command (currently) does not change only based on the local toolchain version go.mod## The go directive in #. It is set up based on dependencies and does not require tracking patch versions.

If your dependencies require at least

go1.21, then your module requires go1.21, forcing go tools Update the go.mod directives in go.mod accordingly. There is no use having your module declare a version prior to go1.21 when building the module actually requires go1.21.

The above is the detailed content of Will "go mod tidy" automatically upgrade the go version in go.mod?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete