douduxia1551 2017-03-13 10:52
浏览 3819
已采纳

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

I have 2 repositories. Let say them repo_a and repo_b. I imported repo_a in repo_b

When I ran go get, it will get repo_a master branch. Is there any way to get develop branch using go get or another command from repo_b?

I do not want to git pull on each specific package (in this case repo_a)

  • 写回答

3条回答 默认 最新

  • dongxia9519 2017-03-13 10:56
    关注

    Stable HEAD philosophy

    It is not possible with pure go get.

    Go takes the most minimal and pragmatic approach of any package manager. There is no such thing as multiple versions of a Go package.

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

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

    You can specify packages with the format, where version can be a revision number (a git/bazaar/mercurial/svn revision hash) or a tag.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?