116

I am trying to compile the InfluxDB database (version v0.8.8) using go get github.com/influxdb/influxdb

But this pulls the master branch, and I need the v0.8.8 tag.

I have tried to do: go get github.com/influxdb/influxdb/releases/tag/v0.8.8 but this fails saying unable to find.

I also tried to do a regular go get of the master branch, and then manually checking out the tag using git in GOPATH/src/github... in order to set the corret version.

The problem using the last approach is that when I try to pull the dependencies with go get -u -f ./... it tries to find them in the master branch, and some of them do not exist on the master branch...

TL;DR: perform go get on a specific github tag, and pull the correct dependencies.

Ivan Aracki
  • 4,861
  • 11
  • 59
  • 73
ESala
  • 6,878
  • 4
  • 34
  • 55
  • Try this.. git tag -a v0.8.8 -"Your comment" – Ashok Londhe May 12 '15 at 10:46
  • 3
    @AshokLondhe He's asking how to use a tag for `go get`, not how to create one. – wonderb0lt May 12 '15 at 10:47
  • @wonderb0lt this is command to add tag. – Ashok Londhe May 12 '15 at 10:48
  • I think I tried finding out how to check out a specific tag as well, and last time I tried it wasn't possible... – wonderb0lt May 12 '15 at 10:49
  • 1
    Have a look at [this](http://www.slideshare.net/poga/dependency-management-in-go). Near the end the slides offer some dependency management alternatives. – wonderb0lt May 12 '15 at 10:52
  • I've never used this tool, but according to the docs it supports tags and revisions as ` ` - [gpm](https://github.com/pote/gpm). It is written in bash, so it might not work for you if you are using Windows. – Makpoc May 12 '15 at 13:10
  • Link to that presentation doesn't work anymore, @wonderb0lt : "This uploaded file has been marked private by the author. Sorry!" – Greg Dubicki May 09 '16 at 11:56
  • For Go 1.11 or higher, see Go Modules: https://stackoverflow.com/questions/53682247/how-to-point-go-module-dependency-in-go-mod-to-a-latest-commit-in-a-repo/ – Everton Oct 04 '19 at 21:02

7 Answers7

36

It is not possible using the go get tool. Instead you need to use a third party go package management tool or create your own forks for the packages that you wish to manage more fine grained.

Spoke to a guy that works at Google and he acknowledged this problem/requirement, he said that vendoring which his team used was bulky and they will probably solve it with the official tools soon.

Read more:

Vendoring in Go 1.6

Vendoring has been released from experimental in go 1.6 (after this post was initially written) that makes the process of using specific tags / versions of packages using third party tools easier. go get does still not have the functionality to fetch specific tags or versions.

More about how vendoring works: Understanding and using the vendor folder

Modules in Go 1.11

Go 1.11 has released an experimental features called modules to improve dependency management, they hope to release it as stable in Go 1.12: Information about modules in Go 1.11

Robin Andersson
  • 5,150
  • 3
  • 25
  • 44
  • 1
    Can you elaborate a bit more about the google part? There's a big discussion of this on the go community's mailing list, is there any other direction that has not been discussed there? – Not_a_Golfer May 12 '15 at 11:43
  • 1
    @Not_a_Golfer It was a guy who wasn't part of the Go team, but talked about that they currently use vendoring internally and that it was quite bulky. So they had an interest in solving it better with the official tools. Think it was an unofficial statement though, will make that more clear. – Robin Andersson May 12 '15 at 12:19
  • 2
    AFAIK, the only proposal is for an official vendor/dependency file format. This is still great, in that projects wouldn't be tied to a dependency tool, and can interoperate with whatever solution they want (i.e. I prefer revision locking, while others prefer vendoring). – JimB May 12 '15 at 18:17
  • modules dont really deal with dependency on code compilers, which forces us to use go get protoc-gen-go somewhere else with fix version. Thus keeping us needing to keep track of the same versioning in 2 different places (because the libraries is tightly coupled with the generator) – Martin Kosicky Aug 06 '19 at 06:35
35

go mod is available now.

For those who need to build a binary of a specific tag, here is my way:

mkdir temp
cd temp
go mod init local/build  # or `go mod init .` before go 1.13
go get -d -v github.com/nsqio/nsq@v1.1.0
mkdir bin
go build -o bin/nsqd.exe github.com/nsqio/nsq/apps/nsqd

Explanation:

  • The above code pulls NSQ v1.1.0 and build nsqd.
  • go mod init . creates a go.mod file in the current directory, which enables using go get with revision/tags. (see this link)
  • -d means "download only", if you want a direct installation, omit this flag and the build commands below this line.
  • -v means "be verbose".
  • The above code is for Windows. If you use Linux, replace bin/nsqd.exe with bin/nsqd.

The module downloaded is stored in %GOPATH%\pkg\mod. If you don't want to pollute your GOPATH directory, make a new one and set your GOPATH to it.

Community
  • 1
  • 1
kbridge4096
  • 901
  • 1
  • 11
  • 22
25

This question predates Go Modules, but for future reference the correct procedure in Go 1.11 for fetching a specific version is this:

go get github.com/influxdb@[version]

Or to get a specific git tag:

go get github.com/influxdb@[gitref]
nik7
  • 806
  • 3
  • 12
  • 20
emidander
  • 2,383
  • 22
  • 29
15

I've had success with this:

  • Run the get command without the tag - it should clone the master branch.
  • Move to the clone directory and checkout the tag or branch that you want.
  • Run the go get command again, it should process the command on the checked out branch.
Gregory Russell
  • 151
  • 1
  • 3
2

In order to update the version of a GO api follow the below steps.

For example I want to update following api to a specific tag.

Actual repo : https://github.com/fraugster/parquet-go

Tags : https://github.com/fraugster/parquet-goreleases/tag/v0.5.0

Go to your root directory

go get -u https://github.com/fraugster/parquet-go@v0.5.0 `

Farid Khan
  • 131
  • 4
1

I have a (somewhat hackish, but working) approach to address this problem, at least for git repositories: As go get'ed packages are normal source control repositories, one can check out tags using normal git tools (could use git from command line, I am using Atlassian SourceTree).

To share my package configuration with my teammates, I have made a git repository out ouf my GOPATH. I then added all packages (at least the ones I wanted to manage this way) to this repo as git submodule. This requires you to move the exising repo folders out of the way and re-add them as git submodule, to not confuse git. This process is somewhat tedious, but proved to be worth the trouble:

I can now commit and push to my GOPATH-repo every timy I use a new go package. When my teammates pull from this repo and issue a git submodule update (or simply update via SoureTree, which does this automatically), their version of the package gets checked out on the same tag as mine is.

Of course this does only work for packages under git source control...

Peter Brennan
  • 1,366
  • 12
  • 28
0

maven golang plugin allows to play with branch, tag and revision during GET, you can take a look at its test for such cases with GIT repository

Igor Maznitsa
  • 833
  • 7
  • 12