简体   繁体   English

如何在 github 存储库的特定标签上执行“go get”

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

I am trying to compile the InfluxDB database (version v0.8.8) using go get github.com/influxdb/influxdb我正在尝试使用go get github.com/influxdb/influxdb编译 InfluxDB 数据库(版本 v0.8.8)

But this pulls the master branch, and I need the v0.8.8 tag.但这会拉动主分支,我需要v0.8.8标签。

I have tried to do: go get github.com/influxdb/influxdb/releases/tag/v0.8.8 but this fails saying unable to find.我试图这样做: go get github.com/influxdb/influxdb/releases/tag/v0.8.8但这失败说无法找到。

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.我还尝试对 master 分支进行常规go get ,然后在GOPATH/src/github...中使用git手动检出标签以设置正确版本。

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...使用最后一种方法的问题是,当我尝试使用go get -u -f ./...拉取依赖项时,它试图在 master 分支中找到它们,而其中一些在 master 分支上不存在.. .

TL;DR : perform go get on a specific github tag, and pull the correct dependencies. TL;DR :在特定的 github 标签上执行go get ,并拉取正确的依赖项。

It is not possible using the go get tool.无法使用go get工具。 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.相反,您需要使用第三方 go 包管理工具或为您希望管理更细粒度的包创建自己的分支。

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.与一位在 Google 工作的人交谈,他承认了这个问题/要求,他说他的团队使用的 vendoring 很庞大,他们可能很快会用官方工具解决它。

Read more:阅读更多:

Vendoring in Go 1.6 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. Vendoring 已经从 go 1.6 中的实验性版本中发布(在这篇文章最初写完之后),这使得使用第三方工具使用特定标签/包版本的过程变得更加容易。 go get does still not have the functionality to fetch specific tags or versions. go get仍然没有获取特定标签或版本的功能。

More about how vendoring works: Understanding and using the vendor folder有关 vendoring 如何工作的更多信息:了解和使用供应商文件夹

Modules in Go 1.11 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 Go 1.11 发布了一个名为 modules 的实验性功能来改进依赖管理,他们希望在 Go 1.12 中将其发布为稳定的:关于 Go 1.11 中模块的信息

go mod is available now. go mod现在可用。

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 .上面的代码拉取 NSQ v1.1.0 并构建nsqd
  • go mod init . creates a go.mod file in the current directory, which enables using go get with revision/tags.在当前目录中创建一个go.mod文件,它允许使用带有修订/标签的go get (see this link ) (见这个链接
  • -d means "download only", if you want a direct installation, omit this flag and the build commands below this line. -d表示“仅下载”,如果您想直接安装,请省略此标志和此行下方的构建命令。
  • -v means "be verbose". -v意思是“冗长”。
  • The above code is for Windows.以上代码适用于Windows。 If you use Linux, replace bin/nsqd.exe with bin/nsqd .如果您使用 Linux,请将bin/nsqd.exe替换为bin/nsqd

The module downloaded is stored in %GOPATH%\\pkg\\mod .下载的模块存储在%GOPATH%\\pkg\\mod If you don't want to pollute your GOPATH directory, make a new one and set your GOPATH to it.如果您不想污染您的GOPATH目录,请创建一个新目录并将您的GOPATH设置GOPATH目录。

I've had success with this:我在这方面取得了成功:

  • Run the get command without the tag - it should clone the master branch.运行没有标签的 get 命令 - 它应该克隆主分支。
  • 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.再次运行 go get 命令,它应该处理检出分支上的命令。

This question predates Go Modules , but for future reference the correct procedure in Go 1.11 for fetching a specific version is this:这个问题早于Go Modules ,但为了将来参考,Go 1.11 中获取特定版本的正确过程是这样的:

go get github.com/influxdb@[version]

Or to get a specific git tag:或者获取特定的 git 标签:

go get github.com/influxdb@[gitref]

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).我有一种(有点 hackish,但有效)方法来解决这个问题,至少对于 git 存储库:因为 go get'ed 包是普通的源代码控制存储库,所以可以使用普通的 git 工具检查标签(可以从命令行使用 git ,我正在使用 Atlassian SourceTree)。

To share my package configuration with my teammates, I have made a git repository out ouf my GOPATH .为了与我的队友分享我的包配置,我在我的 GOPATH 中创建了一个git 存储库 I then added all packages (at least the ones I wanted to manage this way) to this repo as git submodule.然后我将所有包(至少是我想以这种方式管理的包)作为 git 子模块添加到这个 repo 中。 This requires you to move the exising repo folders out of the way and re-add them as git submodule, to not confuse git.这需要您将现有的 repo 文件夹移开,并将它们重新添加为 git 子模块,以免混淆 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.我现在可以在每次使用新的 go 包时提交并推送到我的 GOPATH-repo。 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.当我的队友从这个 repo 中拉取并发出 git 子模块更新(或简单地通过 SoureTree 更新,它会自动执行此操作)时,他们的包版本将在与我的相同的标签上签出。

Of course this does only work for packages under git source control...当然,这只适用于 git 源代码控制下的包......

maven golang 插件允许在 GET 期间使用分支、标记和修订,您可以使用 GIT 存储库查看它对此类情况的测试

In order to update the version of a GO api follow the below steps.要更新 GO api 的版本,请按照以下步骤操作。

For example I want to update following api to a specific tag.例如,我想将以下 api 更新为特定标签。

Actual repo : https://github.com/fraugster/parquet-go实际回购: https : //github.com/fraugster/parquet-go

Tags : https://github.com/fraugster/parquet-goreleases/tag/v0.5.0标签: 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 ` go get -u https://github.com/fraugster/parquet-go@v0.5.0 `

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM