导入与根目录具有相同模块路径的go子目录模块的特定提交。

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

Importing a specific commit of go subdirectory module with same module path as root

问题

我得到了一个托管在私有网站上的代码库,它的结构如下:

a-private-git.com/myrepo/
    go/
        go.mod
        go.sum
        bar.go

该代码库位于 a-private-git.com/myrepo,模块文件为:(请注意,实际上模块本身位于 a-private-git.com/myrepo/go

module a-private-git.com/myrepo

我能否包含该代码库的特定提交/分支?还是我需要代码库的提供者进行更改?

我尝试过:

go get a-private-git.com/myrepo@v0.0.0-<commit time>-<commit hash>
> 模块已添加到 go.mod,但构建时出现以下错误:
> 没有提供 a-private-git.com/myrepo 的所需模块;要添加它:
>    go get a-private-git.com/myrepo

go get a-private-git.com/myrepo/go@v0.0.0-<commit time>-<commit hash>
> 模块将其路径声明为:a-private-git.com/myrepo
>     但需要的路径为:a-private-git.com/myrepo/go

(基于 https://go.dev/doc/modules/managing-source)
go get a-private-git.com/myrepo/go@go/v0.0.0-<commit time>-<commit hash>
> 无效的版本:未知的修订版本 go/v0.0.0-<commit time>-<commit hash>
英文:

I am given a repository hosted on a private site, and it looks like this:

a-private-git.com/myrepo/
    go/
        go.mod
        go.sum
        bar.go

The repository is located at a-private-git.com/myrepo and the module file is: (Note that the module itself is actually located at a-private-git.com/myrepo/go)

module a-private-git.com/myrepo

Is it possible to include a specific commit/branch of this repository? Or do I need the provider of the repo to change it?

I've tried:

go get a-private-git.com/myrepo@v0.0.0-&lt;commit time&gt;-&lt;commit hash&gt;
&gt; the module is added to go.mod, but when I build I get:
&gt; no required module provides package a-private-git.com/myrepo; to add it: 
&gt;    go get a-private-git.com/myrepo

go get a-private-git.com/myrepo/go@v0.0.0-&lt;commit time&gt;-&lt;commit hash&gt;
&gt; module declares its path as: a-private-git.com/myrepo
&gt;     but was required as: a-private-git.com/myrepo/go

(Based on https://go.dev/doc/modules/managing-source)
go get a-private-git.com/myrepo/go@go/v0.0.0-&lt;commit time&gt;-&lt;commit hash&gt;
&gt; invalid version: unknown revision go/v0.0.0-&lt;commit time&gt;-&lt;commit hash&gt;

答案1

得分: 1

最简单的方法是直接使用go get命令获取你想要的提交哈希值:

go get a-private-git.com/myrepo@commit_hash

或者你可以使用分支名称获取最新的提交:

go get a-private-git.com/myrepo@branch_name
英文:

The easieset way would be to simply 'go get' the commit hash you want:

go get a-private-git.com/myrepo@commit_hash

Alternatively you can use a branch name to get its latest commit:

go get a-private-git.com/myrepo@branch_name

huangapple
  • 本文由 发表于 2022年12月19日 18:26:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/74849197.html
匿名

发表评论

匿名网友

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

确定