简体   繁体   English

如何使用go get获取另一个分支而不是默认分支

[英]How to get another branch instead of default branch with go get

I have 2 repositories. 我有2个存储库。 Let say them repo_a and repo_b. 让他们说repo_a和repo_b。 I imported repo_a in repo_b 我在repo_b中导入了repo_a

When I ran go get, it will get repo_a master branch. 当我跑去get时,它将获得repo_a master分支。 Is there any way to get develop branch using go get or another command from repo_b? 有没有办法使用go get或repo_b中的其他命令来获取开发分支?

I do not want to git pull on each specific package (in this case repo_a) 我不想git pull每个特定的包(在这种情况下repo_a)

Stable HEAD philosophy 稳定的HEAD理念

It is not possible with pure go get . 纯粹的go get是不可能的。

Go takes the most minimal and pragmatic approach of any package manager. Go采用任何包管理器最简单实用的方法。 There is no such thing as multiple versions of a Go package. 没有多个版本的Go包这样的东西。

But this is not as bad as it seems at the first view because there exists a philosophy behind this behavior. 但这并不像第一种观点那样糟糕,因为这种行为背后存在一种哲学。

As a package author, you must adhere to the stable HEAD philosophy. 作为包装作者,您必须遵守稳定的HEAD理念。 Your default branch must always be the stable, released version of your package. 您的默认分支必须始终是包的稳定版本。 You must do work in feature branches and only merge when ready to release. 您必须在功能分支中工作,并且只有在准备发布时才合并。

This approach is forced by go get limitations and it should be treated like Python indentations - it is kind of philosophy forced by language design. 这种方法go get限制的限制,应该像Python缩进一样对待 - 这是一种由语言设计强迫的哲学。

Development approaches 发展方式

If you want to fork something or try new features you can clone repo then switch to a desired branch and do go build . 如果您想要分叉或尝试新功能,您可以克隆repo然后切换到所需的分支并进行go build This way shouldn't go to production. 这种方式不应该去生产。

git clone <repo name>
cd <repo name>
git checkout <branch name>
go build

Also you can use third party package management tools. 您也可以使用第三方软件包管理工具。 But most of them support tags and revisions, not branches (since it is implied that you don't need to install feature branch). 但是大多数都支持标签和修订,而不支持分支(因为暗示您不需要安装功能分支)。

gpm : gpm

You can specify packages with the format, where version can be a revision number (a git/bazaar/mercurial/svn revision hash) or a tag. 您可以使用格式指定包,其中version可以是修订号(git / bazaar / mercurial / svn修订版哈希)或标记。

you can use gopkg.in , it will redirect to github. 你可以使用gopkg.in ,它将重定向到github。

There are two URL patterns supported: 支持两种URL模式:

gopkg.in/pkg.v3      → github.com/go-pkg/pkg (branch/tag v3, v3.N, or v3.N.M)
gopkg.in/user/pkg.v3 → github.com/user/pkg   (branch/tag v3, v3.N, or v3.N.M)

go get gopkg.in/pkg.v3 means go get github.com/go-pkg/pkg , but is branch or tag v3.* . go get gopkg.in/pkg.v3表示go get github.com/go-pkg/pkg ,但是分支或标记为v3.*

for more details, see here 有关详细信息,请参阅此处

Starting with Go 1.11, this is possible when using Go modules . 从Go 1.11开始,这可以在使用Go模块时实现 When installing a dependency for a Go module, you can specify a module query which may contain a branch or tag name: 在为Go模块安装依赖项时,您可以指定可能包含分支或标记名称的模块查询

$ go get <path-to-repo>@<branch>

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

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