目錄
問題內容
解決方法
首頁 後端開發 Golang git ls-remote 成功而 go get 失敗

git ls-remote 成功而 go get 失敗

Feb 14, 2024 pm 01:54 PM
go語言

git ls-remote 成功而 go get 失败

php小編蘋果在使用Git和Go語言開發專案時,遇到了一個問題:git ls-remote指令能夠成功取得遠端倉庫的信息,但是使用go get指令卻無法成功下載依賴的套件。這個問題困擾了小編很長一段時間,經過不斷的嘗試和調試,最終找到了解決方案。在本文中,將詳細介紹這個問題的原因以及解決方法,希望能對遇到相同問題的開發者有所幫助。

問題內容

git ls-remote 指令對儲存庫成功,如下所示。

git ls-remote https://internal.net/dir1/dir2/dir3/repo
warning: redirecting to https://internal.net/dir1/dir2/dir3/repo.git/
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    head
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy    refs/heads/master
登入後複製

但是,當使用 go get 時,cmd 會失敗並找不到儲存庫。錯誤輸出嘗試在儲存庫結構上方的 1 個目錄中尋找 .git。

go get internal.net/dir1/dir2/dir3/repo@master
go: internal.net/dir1/dir2/dir3/repo@master: invalid version: git ls-remote -q origin in /Users/{{UserId}}/go/pkg/mod/cache/vcs/xyz...: exit status 128:
    remote: The project you were looking for could not be found or you don't have permission to view it.
    fatal: repository 'https://internal.net/dir1/dir2.git/' not found
登入後複製

我的私有化是 goprivate=internal.net

為了讓 go get 成功,我在這裡缺少什麼?

解決方法

在私有模組路徑中加入vcs後綴以標記儲存庫根前綴:

go get internal.net/dir1/dir2/dir3/repo.git@master
登入後複製

請參閱直接存取私有模組

可能仍然需要內部 http 伺服器來將模組路徑解析為儲存庫 url 。例如,當go 指令下載模組corp.example.com/mod 時,它會向 https://corp.example.com/mod?go-get=1 傳送get請求,並會尋找儲存庫回應中的url。為了避免此要求,請確保每個私有模組路徑都有一個 vcs 後綴(如 .git),標記儲存庫根前綴。例如,當go 指令下載模組corp.example.com/repo.git/mod 時,它將複製位於 https://corp.example.com/repo.gitssh://corp.example 的git 儲存庫.com/repo.git,無需發出額外請求。

請注意,vcs 後綴是模組路徑的一部分,因此應將其包含在所有使用模組路徑的地方。包括:

  1. module 指令

    module internal.net/dir1/dir2/dir3/repo.git
    登入後複製
  2. require 指令

    require internal.net/dir1/dir2/dir3/repo.git v0.0.1
    登入後複製
  3. 進口報關

    import "internal.net/dir1/dir2/dir3/repo.git/pkg/util"
    登入後複製
  4. 還有更多。

  5. 以上是git ls-remote 成功而 go get 失敗的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

golang 如何使用反射存取私有欄位和方法 golang 如何使用反射存取私有欄位和方法 May 03, 2024 pm 12:15 PM

golang 如何使用反射存取私有欄位和方法

golang函數動態建立新函數的技巧 golang函數動態建立新函數的技巧 Apr 25, 2024 pm 02:39 PM

golang函數動態建立新函數的技巧

Go語言中的效能測試與單元測試的差異 Go語言中的效能測試與單元測試的差異 May 08, 2024 pm 03:09 PM

Go語言中的效能測試與單元測試的差異

Golang技術在設計分散式系統時應注意哪些陷阱? Golang技術在設計分散式系統時應注意哪些陷阱? May 07, 2024 pm 12:39 PM

Golang技術在設計分散式系統時應注意哪些陷阱?

Golang技術在機器學習中使用的函式庫和工具 Golang技術在機器學習中使用的函式庫和工具 May 08, 2024 pm 09:42 PM

Golang技術在機器學習中使用的函式庫和工具

Golang技術在行動物聯網開發中的作用 Golang技術在行動物聯網開發中的作用 May 09, 2024 pm 03:51 PM

Golang技術在行動物聯網開發中的作用

golang函數命名約定的演變 golang函數命名約定的演變 May 01, 2024 pm 03:24 PM

golang函數命名約定的演變

golang可變參數是否可以用於函數傳回值? golang可變參數是否可以用於函數傳回值? Apr 29, 2024 am 11:33 AM

golang可變參數是否可以用於函數傳回值?

See all articles