如何在 GitHub 存储库的特定标签上执行 “go get” 操作?

huangapple go评论94阅读模式
英文:

How to do "go get" on a specific tag of a github repository

问题

我正在尝试使用go get github.com/influxdb/influxdb编译InfluxDB数据库(版本v0.8.8)。

但是这会拉取主分支,而我需要v0.8.8标签。

我尝试过执行go get github.com/influxdb/influxdb/releases/tag/v0.8.8,但是失败了,显示无法找到。

我还尝试过正常执行go get来获取主分支,然后在GOPATH/src/github...中使用git手动检出标签,以设置正确的版本。

使用最后一种方法的问题是,当我尝试使用go get -u -f ./...拉取依赖项时,它会尝试在主分支中找到它们,而主分支上有些依赖项不存在...

TL;DR:在特定的GitHub标签上执行go get,并拉取正确的依赖项。

英文:

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.

答案1

得分: 36

使用go get工具是不可能的。相反,您需要使用第三方的Go包管理工具或者为您希望更细粒度管理的包创建自己的分支。

我和一个在Google工作的人谈过,他承认了这个问题/需求,他说他们团队使用的vendoring方法很笨重,他们可能会很快用官方工具解决这个问题。

了解更多:

Go 1.6中的Vendoring

Vendoring已经从实验性功能中发布到了go 1.6中(在本文最初编写之后),这使得使用第三方工具来使用特定标签/版本的包的过程更加容易。go get仍然没有获取特定标签或版本的功能。

关于vendoring的更多信息:理解和使用vendor文件夹

Go 1.11中的模块

Go 1.11发布了一个名为模块的实验性功能,旨在改进依赖管理,他们希望在Go 1.12中将其发布为稳定版本:关于Go 1.11中模块的信息

英文:

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

答案2

得分: 34

go mod现在可用。

对于那些需要构建特定标签的二进制文件的人,这是我的方法:

mkdir temp
cd temp
go mod init local/build  # 或者在 go 1.13 之前使用 `go mod init .`
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

解释:

  • 上述代码拉取了 NSQ v1.1.0 并构建了 nsqd
  • go mod init . 在当前目录中创建了一个 go.mod 文件,这使得可以使用带有修订版本/标签的 go get。(参见此链接
  • -d 表示“仅下载”,如果你想要直接安装,省略此标志和下面这行之后的构建命令。
  • -v 表示“显示详细信息”。
  • 上述代码适用于 Windows。如果你使用 Linux,请将 bin/nsqd.exe 替换为 bin/nsqd

下载的模块存储在 %GOPATH%\pkg\mod 中。如果你不想污染你的 GOPATH 目录,可以创建一个新目录并将你的 GOPATH 设置为该目录。

英文:

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.

答案3

得分: 24

这个问题是在Go Modules之前提出的,但是以后参考的话,在Go 1.11中获取特定版本的正确步骤是这样的:

go get github.com/influxdb@[version]

或者获取特定的git标签:

go get github.com/influxdb@[gitref]
英文:

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]

答案4

得分: 15

我已经成功地完成了这个操作:

  • 运行不带标签的 get 命令 - 它应该克隆主分支。
  • 进入克隆目录并检出你想要的标签或分支。
  • 再次运行 go get 命令,它应该在检出的分支上处理该命令。
英文:

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.

答案5

得分: 2

为了更新GO API的版本,请按照以下步骤进行操作。

例如,我想将以下API更新到特定的标签。

实际仓库:https://github.com/fraugster/parquet-go

标签:https://github.com/fraugster/parquet-go/releases/tag/v0.5.0

进入你的根目录

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

英文:

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

`

答案6

得分: 1

我有一种(有点破解但有效的)方法来解决这个问题,至少对于git仓库来说是这样的:由于go get的包是普通的源代码控制仓库,我们可以使用普通的git工具(可以使用命令行中的git,我使用的是Atlassian SourceTree)来检出标签。

为了与我的团队共享我的包配置,我将我的GOPATH作为一个git仓库。然后,我将所有的包(至少是我想以这种方式管理的包)作为git子模块添加到这个仓库中。这需要你将现有的仓库文件夹移出并重新添加为git子模块,以免混淆git。这个过程有点繁琐,但证明是值得的:

现在,每当我使用一个新的go包时,我可以提交和推送到我的GOPATH仓库。当我的团队成员从这个仓库拉取并执行git submodule update(或者简单地通过SourceTree更新,它会自动执行此操作)时,他们的包版本将与我的版本一致。

当然,这只适用于使用git源代码控制的包...

英文:

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...

答案7

得分: 0

maven golang plugin 允许在 GET 过程中处理分支、标签和修订版本,你可以查看 其与 GIT 仓库一起使用的测试

英文:

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

huangapple
  • 本文由 发表于 2015年5月12日 18:43:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/30188499.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定