【问题标题】:Invalid version and https references when importing private repo in golang在 golang 中导入私有 repo 时版本和 https 引用无效
【发布时间】:2020-07-23 21:43:33
【问题描述】:

尝试在 golang 中导入私有 repo 作为包。做到了:

git config --global url.git@github.com:.insteadOf https://github.com/

所以理论上所有对 https 的引用都会被 ssh 版本取代。

github.com/XXX/util

是我的私人仓库,它是一个 go 模块。

我执行 go get -v 并获取:

[gabriel@xiridio backend]$ go get -v
go: finding module for package github.com/XXX/util
go: downloading github.com/XXX/util v0.0.0-20200411022955-454673685ff5
go: finding module for package github.com/XXX/util
main.go:12:2: github.com/XXX/util@v0.0.0-20200411022955-454673685ff5: verifying module: github.com/XXX/util@v0.0.0-20200411022955-454673685ff5: reading https://sum.golang.org/lookup/github.com/!X!X!X/util@v0.0.0-20200411022955-454673685ff5: 410 Gone
        server response:
        not found: github.com/XXX/util@v0.0.0-20200411022955-454673685ff5: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/f1fdc5cc42a6995f954688df06783c05d28e4a60e9aaf6930a88a2487b913907: exit status 128:
                fatal: could not read Username for 'https://github.com': terminal prompts disabled

看起来存在“版本”问题,而且由于某种原因,仍然存在对 https 的引用。我还能做什么?

【问题讨论】:

    标签: git go


    【解决方案1】:

    为了确定,我更喜欢在 git config 命令中使用引号:

    git config --global url."git@github.com:".insteadOf "https://github.com/"
    

    看到这个gist as an example

    它包括:

    使用git@github.com 的另一种方法是在您的 GitHub 帐户上生成个人访问令牌,授予其存储库访问权限,然后改用以下命令:

    git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"
    

    还要检查“go get results in 'terminal prompts disabled' error for GitHub private repo”,其中提到了GOPRIVATE 的使用。

    【讨论】:

    • 谢谢。使用 git config 和 GOPRIVATE 工作。
    • @GabrielA.Zorrilla 您使用了两个git config 中的哪一个?
    • 引号对 ~/.gitconfig 的输出没有任何影响,因此两者都是有效的。
    猜你喜欢
    • 1970-01-01
    • 2018-10-06
    • 2019-04-03
    • 2016-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-21
    相关资源
    最近更新 更多