英文:
import from specific branch github in the same repository where it is hosted
问题
我有一个在Github上的Go项目仓库,我需要在一个模块中导入一个特定的分支,以进行相关修改。代码如下:
import (
"github.com/repository/utils/date_utils"
"github.com/repository/utils/utils/error_utils"
"github.com/repository/utils/utils/hour_utils"
"strconv"
"strings"
)
导入操作通常直接从主分支进行。我只需要这个模块从不同的分支进行导入。
英文:
I have a repository with a Go project in Github, I need to import in a module a specific branch, to make relevant modifications. It looks like this:
import (
"github.com/repository/utils/date_utils"
"github.com/repository/utils/utils/error_utils"
"github.com/repository/utils/utils/hour_utils"
"strconv"
"strings"
)
The import is always done directly from the master. I just need this module to import from a different branch.
答案1
得分: 5
你可以使用以下命令进行安装:
go get <path-to-repo>@<branch>
根据文档的说明:
go get
会将命令行参数解析为特定模块版本的包,更新go.mod
文件以要求这些版本,将源代码下载到模块缓存中,然后构建和安装指定的包。
此外,文档中的这一行也很有意思:
使用类似
go get foo@master
(使用Mercurial时为foo@default
)的分支名称是一种获取最新提交的方法,无论是否有语义化版本标签。
英文:
you can use
go get <path-to-repo>@<branch>
From documentation
> Get resolves its command-line arguments to packages at specific module
> versions, updates go.mod to require those versions, downloads source
> code into the module cache, then builds and installs the named
> packages
Also this particular line on the documentation is interesting as-well.
> Using a branch name such as go get foo@master (foo@default with mercurial) is one way to obtain the latest commit regardless of whether or not it has a semver tag.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论