在同一仓库中,从特定分支的 GitHub 上导入代码。

huangapple go评论88阅读模式
英文:

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 &lt;path-to-repo&gt;@&lt;branch&gt;

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.

huangapple
  • 本文由 发表于 2021年8月1日 00:18:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/68603850.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定