2

I 'd like to pin the version of one package, so whenever I run

go get -u ./...

..this package would stay unchanged (but the rest refreshed normally).

vbence
  • 20,084
  • 9
  • 69
  • 118

1 Answers1

2

Use go modules. It was specifically designed to handle precise version control.

In your package's go.mod you can pin any dependencies to a fixed version e.g.

module example.com/hello
go 1.12
require (
    golang.org/x/text v0.3.0 // indirect
    rsc.io/quote v1.5.2
    rsc.io/quote/v3 v3.0.0
    rsc.io/sampler v1.3.1 // indirect
)

You can update individual package versions e.g.:

go get rsc.io/quote/v3@master

Will pull the latest commit version (beyond even any semver tagged version). You can also hand edit go.mod for extra precision.

P.S. you need go version 1.11 or later for go modules. go 1.13 has modules turned on by default. Earlier versions you have to explicitly enable it via the env var GO111MODULE=ON.

colm.anseo
  • 19,337
  • 4
  • 43
  • 52
  • Thanks. I'm already using go-modules, the problem is that there are too many dependencies to update them one-by-one, that's why `go get -u ./...` would be useful for me. Is there an alternative way to do a general upgrade? – vbence May 31 '20 at 17:10
  • You can clone the repo you want to fix to a local directory. Then use the `replace` directive in `go.mod` - this will prevent go-build from using an internet version of the pkg - but use the local (fixed) copy. – colm.anseo May 31 '20 at 17:40