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="//m.sbmmt.com/link/89fee0513b6668e555959f5dc23238e9" class="__cf_email__" data-cfemail="10777964507779647c71723e6764763e7e7f64677f627b797e77">[email protected]</a>:2224/"] insteadof = https://gitlab.wtf.notworking/
用“:”
[url "<a href="//m.sbmmt.com/link/89fee0513b6668e555959f5dc23238e9" class="__cf_email__" data-cfemail="e4838d90a4838d90888586ca939082ca8a8b90938b968f8d8a83">[email 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中文网其他相关文章!