使用 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://[email protected]:2224/"]
insteadof = https://gitlab.wtf.notworking/
用“:”
[url "[email protected]: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 项目:未知修订版的详细内容,更多请关注编程网其它相关文章!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341