Previously the project was using go 1.20 in go.mod. I've upgrade my go version to 1.21.0 on local linux machine.
When I run go mod tidy for the project, it upgraded go.mod to use go 1.21.0 automatically.
If this is the expected behavior, is there a way to disable this behaviour, aka. don't auto update the go version in go.mod when run go mod tidy? Because others might didn't upgrade locally yet.
The
go mod tidycommand does not (currently) alter thegodirective ingo.modbased only on the local toolchain version. It sets it based on dependencies, and does not need to track patch versions.If you have a dependency that requires a minimum of
go1.21, then your module requiresgo1.21, forcing thegotool to update thegodirective ingo.modaccordingly. It would not be of any use to have your module declare a version prior togo1.21whengo1.21is actually required to build the module.