登录
首页 >  Golang >  Go问答

Golang go 使用 git ls-remote -q 使用错误的 url @ Go 1.13 失败

来源:stackoverflow

时间:2024-05-01 15:54:35 215浏览 收藏

golang学习网今天将给大家带来《Golang go 使用 git ls-remote -q 使用错误的 url @ Go 1.13 失败》,感兴趣的朋友请继续看下去吧!以下内容将会涉及到等等知识点,如果你是正在学习Golang或者已经是大佬级别了,都非常欢迎也希望大家都能给我建议评论哈~希望能帮助到大家!

问题内容

好的,根据https://github.com/golang/go/issues/34094,go 1.13.3修复了这个问题

环境:go 1.13,windows

我在 windows 计算机上获得了一份新的 go 副本,并尝试在这里构建我的项目。

但是,曾经有效的 mod 现在失败了:

C:\xxx> go get -v private.repo.com/dir/utils.git
get "private.repo.com/dirxxxx": found meta tag get.metaImport{Prefix:"private.repo.com/dirxxxx", VCS:"git", RepoRoot:"https://private.repo.com/dirxxxx.git"} at //private.repo.com/dirxxxx?go-get=1
get "private.repo.com": found meta tag get.metaImport{Prefix:"private.repo.com", VCS:"git", RepoRoot:"https://private.repo.com.git"} at //private.repo.com/?go-get=1
go: finding private.repo.com/dirxxxx/utils.git v0.0.5
go: downloading private.repo.com/dirxxxx/utils.git v0.0.5
go: extracting private.repo.com/dirxxxx/utils.git v0.0.5
go get private.repo.com/dirxxxx/utils.git: git ls-remote -q https://private.repo.com/dirxxxx.git in C:\Users\admin\go\pkg\mod\cache\vcs\227f0870299637a3fadb469f608679095de39005c860e3949d82a547e8c30143: exit status 128:
        GitLab: The project you were looking for could not be found.
        fatal: Could not read from remote repository.

        Please make sure you have the correct access rights
        and the repository exists.

这并没有错,因为确实没有 https://private.repo.com/dirxxxx.git。

我们拥有的是 https://private.repo.com/dirxxxx/utils.git。我怎样才能强制 go git 使用某个标签或跳过 ls-remote 因为它已经找到了一个版本并提取文件哈哈

我根据 https://golang.org/doc/go1.13 配置 goproxy=direct ,因为我使用的是私人存储库。

还按照指南设置代理和其他内容,但问题仍然存在。

有什么建议吗?提前致谢!


解决方案


别名

如果您已将存储库从 https://private.repo.com/dirxxxx.git 移动到 https://private.repo.com/dirxxxx/utils.git,则可以在 go.mod 中使用 replace directive文件定义别名路径:

replace private.repo.com/dirxxxx => private.repo.com/dirxxxx/utils v0.0.5

这样,当您运行 go get private.repo.com/dirxxxx 时,它将改为从 https://private.repo.com/dirxxxx/utils.git 获取。

https 身份验证

如果您的存储库受密码保护,您可以使用用户名和密码配置您的 git,如下所示:

git config --global url."https://username:[email protected]/".insteadof "https://private.repo.com/"

这会在您的 ~/.gitconfig 中生成一个部分,如下所示:

[url "https://username:[email protected]/"]
    insteadOf = https://private.repo.com/

理论要掌握,实操不能落!以上关于《Golang go 使用 git ls-remote -q 使用错误的 url @ Go 1.13 失败》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>