首頁 >後端開發 >Golang >使用 ssh 從私人 gilab 儲存庫匯入 go 專案:未知修訂版

使用 ssh 從私人 gilab 儲存庫匯入 go 專案:未知修訂版

WBOY
WBOY轉載
2024-02-09 11:24:081073瀏覽

使用 ssh 从私有 gilab 存储库导入 go 项目:未知修订版

php小編西瓜為你介紹如何使用SSH從私有GitLab儲存庫匯入Go專案的未知修訂版。透過SSH連接到GitLab,可以方便地將專案匯入到本機環境中進行修改和開發。本文將詳細解釋導入過程中的每個步驟,以便讀者能夠輕鬆地完成操作。在繼續之前,請確保已經安裝了Git和Go,並且已經在GitLab上建立了一個私人儲存庫。讓我們開始吧!

問題內容

我正在嘗試使用 ssh 從私有且自託管的 gitlab 儲存庫匯入 go 專案。當我嘗試這樣做時,出現以下錯誤。

輸出

kbacon@kbacons-macbook-pro bbz % go get -x gitlab.wtf.notworking/bbq/tools@latest
# get https://gitlab.wtf.notworking/bbq/tools?go-get=1
# get https://gitlab.wtf.notworking/bbq/tools?go-get=1: 200 ok (0.413s)
mkdir -p /users/kbacon/go/pkg/mod/cache/vcs # git3 https://gitlab.wtf.notworking/bbq/tools.git
# lock /users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179.lock# /users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179 for git3 https://gitlab.wtf.notworking/bbq/tools.git
cd /users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git tag -l
0.013s # cd /users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git tag -l
cd /users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git ls-remote -q origin
0.020s # cd /users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git ls-remote -q origin
# get https://gitlab.wtf.notworking/bbq/tools.git
# get https://gitlab.wtf.notworking/bbq/tools.git: 200 ok (0.186s)
go: gitlab.wtf.notworking/bbq/[email protected]: reading gitlab.wtf.notworking/bbq/tools/go.mod at revision v1.0.0: unknown revision v1.0.0

.gitconfig

[user]
        name = kbacon
        email = [email protected]
[url "[email protected]/"]
        insteadof = https://gitlab.wtf.notworking/

去mod檔

module bbz
go 1.14
require (
    gitlab.wtf.notworking/bbq/tools v1.0.0
)

gitlab 倉庫

gitlab 倉庫有一個發佈標籤 v1.0.0 的專案

我用來克隆的位址

ssh://[email protected]:2224/bbq/tools.git

ssh 設定檔

host gitlab.wtf.notworking
    user [email protected]
    hostname gitlab.wtf.notworking
    identityfile ~/.ssh/company_gitlab # path to private key
    addkeystoagent yes

使用這個 .gitconfig: .gitconfig

[user]
        name = kbacon
        email = [email protected]
[url "[email protected]:2224/"]
        insteadof = https://gitlab.wtf.notworking/

然後 go get 指令會請求我的密碼,但它應該使用 ssh。為什麼它要求我輸入密碼?

kbacon@kbacons-MacBook-Pro bbz % go get -x gitlab.wtf.notworking/bbq/tools@latest
# get https://gitlab.wtf.notworking/bbq/tools?go-get=1
# get https://gitlab.wtf.notworking/bbq/tools?go-get=1: 200 OK (0.424s)
mkdir -p /Users/kbacon/go/pkg/mod/cache/vcs # git3 https://gitlab.wtf.notworking/bbq/tools.git
# lock /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179.lock# /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179 for git3 https://gitlab.wtf.notworking/bbq/tools.git
cd /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git tag -l
0.030s # cd /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git tag -l
cd /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git ls-remote -q origin
[email protected]'s password:

解決方法

如果您使用ssh url 為/ 而不是:,您的.gitconfig 應該是:

[url "ssh://<a href="https://www.php.cn/link/89fee0513b6668e555959f5dc23238e9" class="__cf_email__" data-cfemail="10777964507779647c71723e6764763e7e7f64677f627b797e77">[email&#160;protected]</a>:2224/"]
        insteadof = https://gitlab.wtf.notworking/

用「:」

[url "<a href="https://www.php.cn/link/89fee0513b6668e555959f5dc23238e9" class="__cf_email__" data-cfemail="e4838d90a4838d90888586ca939082ca8a8b90938b968f8d8a83">[email&#160;protected]</a>:2224:"]
        insteadof = https://gitlab.wtf.notworking/

在您的 ssh 設定檔中,請確保使用服務帳戶 git,而不是您的登入名稱、連接埠和自訂主機項目:

host gitlab-wtf
    user git
    hostname gitlab.wtf.notworking
    identityfile ~/.ssh/company_gitlab # path to private key
    addkeystoagent yes
    port 2224

這樣,您就可以使用:

[url "ssh://gitlab-wtf/"]
        insteadof = https://gitlab.wtf.notworking/

不再有 git@:2224

以上是使用 ssh 從私人 gilab 儲存庫匯入 go 專案:未知修訂版的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:stackoverflow.com。如有侵權,請聯絡admin@php.cn刪除