英文:
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-<commit time>-<commit hash>
> the module is added to go.mod, but when I build I get:
> no required module provides package a-private-git.com/myrepo; to add it:
> go get a-private-git.com/myrepo
go get a-private-git.com/myrepo/go@v0.0.0-<commit time>-<commit hash>
> module declares its path as: a-private-git.com/myrepo
> 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-<commit time>-<commit hash>
> invalid version: unknown revision go/v0.0.0-<commit time>-<commit hash>
答案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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论