![](/img/trans.png)
[英]go get private repo fails due to missing .git when importing from Azure DevOps repositories
[英]Invalid version and https references when importing private repo in golang
嘗試在 golang 中將私有倉庫導入為 package。 做過:
git config --global url.git@github.com:.insteadOf https://github.com/
所以理論上所有對 https 的引用都被 ssh 版本取代。
github.com/XXX/util
是我的私人倉庫,它是一個 go 模塊。
我做了一個 go 得到 -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。 我還可以做些什么?
為了能夠使用go 1.18
拉出我的私有模塊,我必須做兩件事:
~/.gitconfig
中添加了以下兩行:[url "ssh://git@github.com/"]
insteadOf = https://github.com/
go env -w GOPRIVATE="github.com/projname/mod1,github.com/projname/mod2,github.com/projname/mod3"
我認為這是必要和充分的,或者至少是足夠的。
請注意,您需要使用 ssh 對您的私人存儲庫進行本地訪問才能正常工作。
可以肯定的是,我更喜歡在 git 配置命令中使用引號:
git config --global url."git@github.com:".insteadOf "https://github.com/"
以這個要點為例。
這包括:
使用
git@github.com
的替代方法是在您的 GitHub 帳戶上生成個人訪問令牌,授予其 repo 訪問權限,然后使用以下命令代替: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
的使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.