git 如何在 github 存储库的特定标签上执行“go get”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30188499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to do "go get" on a specific tag of a github repository
提问by ESala
I am trying to compile the InfluxDB database (version v0.8.8) using go get github.com/influxdb/influxdb
我正在尝试使用编译 InfluxDB 数据库(版本 v0.8.8) go get github.com/influxdb/influxdb
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.
我还尝试对go get
master 分支进行常规检查,然后使用git
in手动检查标签GOPATH/src/github...
以设置 corret 版本。
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:go get
在特定的 github 标签上执行,并拉取正确的依赖项。
采纳答案by Robin Andersson
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.
无法使用该go get
工具。相反,您需要使用第三方 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:
阅读更多:
- Reference of third party package management tools
- Blog post by golang team discussing the approach for implementing vendoring
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. go get
does still not have the functionality to fetch specific tags or versions.
Vendoring 已经从 go 1.6 中的实验性版本中释放出来(在这篇文章最初写完之后),这使得使用第三方工具使用特定标签/版本的包的过程变得更加容易。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 中模块的信息
回答by brk
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 .
go get -d -v github.com/nsqio/[email protected]
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 ago.mod
file in the current directory, which enables usinggo 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
withbin/nsqd
.
- 上面的代码拉取 NSQ v1.1.0 并构建
nsqd
. go mod init .
go.mod
在当前目录中创建一个文件,该文件可以go get
与修订版/标签一起使用。(见这个链接)-d
表示“仅下载”,如果您想直接安装,请省略此标志和此行下方的构建命令。-v
意思是“冗长”。- 以上代码适用于Windows。如果您使用 Linux,请替换
bin/nsqd.exe
为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.
下载的模块存储在%GOPATH%\pkg\mod
. 如果您不想污染您的GOPATH
目录,请创建一个新目录并将其设置GOPATH
为。
回答by Gregory Russell
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.
- 运行没有标签的 get 命令 - 它应该克隆主分支。
- 移至克隆目录并签出所需的标记或分支。
- 再次运行 go get 命令,它应该处理检出分支上的命令。
回答by Peter Hommel
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. 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:
为了与我的队友分享我的包配置,我在我的 GOPATH 中创建了一个git 存储库。然后我将所有包(至少是我想以这种方式管理的包)作为 git 子模块添加到这个 repo 中。这需要您将现有的 repo 文件夹移开,并将它们重新添加为 git 子模块,以免混淆 git。这个过程有点乏味,但事实证明是值得的:
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.
我现在可以在每次使用新的 go 包时提交并推送到我的 GOPATH-repo。当我的队友从这个 repo 中拉取并发出 git 子模块更新(或简单地通过 SoureTree 更新,它会自动执行此操作)时,他们的包版本将在与我的相同的标签上签出。
Of course this does only work for packages under git source control...
当然,这只适用于 git 源代码控制下的包......
回答by Igor Maznitsa
maven golang pluginallows to play with branch, tag and revision during GET, you can take a look at its test for such cases with GIT repository
maven golang 插件允许在 GET 期间使用分支、标记和修订,您可以使用 GIT 存储库查看它对此类情况的测试
回答by emidander
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]
go get github.com/influxdb@[version]
Or to get a specific git tag:
或者获取特定的 git 标签:
go get github.com/influxdb@[gitref]
go get github.com/influxdb@[gitref]