从私有的GitLab仓库使用SSH导入一个Go项目:未知的版本。

huangapple go评论87阅读模式
英文:

importing a go project from a private gilab repo using ssh: unknown revision

问题

我正在尝试使用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/tools@v1.0.0: reading gitlab.wtf.notworking/bbq/tools/go.mod at revision v1.0.0: unknown revision v1.0.0

.gitconfig 文件:

[user]
        name = kbacon
        email = kbacon@email.com
insteadof = https://gitlab.wtf.notworking/

go mod 文件:

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

GitLab 仓库:

该GitLab仓库有一个带有发布标签 v1.0.0 的项目。

我用于克隆的地址:

ssh://git@gitlab.wtf.notworking:2224/bbq/tools.git

ssh 配置文件:

Host gitlab.wtf.notworking
    User kbacon@email.com
    Hostname gitlab.wtf.notworking
    IdentityFile ~/.ssh/company_gitlab # 私钥路径
    AddKeysToAgent yes

使用以下 .gitconfig 文件:

.gitconfig

[user]
        name = kbacon
        email = kbacon@email.com
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
git@gitlab.wtf.notworking's password:
英文:

I am trying to import a go project from a private and self hosted gitlab repo using ssh. When i try to do so, i get the following error.

output

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/tools@v1.0.0: reading gitlab.wtf.notworking/bbq/tools/go.mod at revision v1.0.0: unknown revision v1.0.0

.gitconfig

[user]
        name = kbacon
        email = kbacon@email.com
insteadof = https://gitlab.wtf.notworking/

go mod file

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

gitlab repo

the gitlab repo has a project with a release tag v1.0.0

The address i use to clone

ssh://git@gitlab.wtf.notworking:2224/bbq/tools.git

ssh config file

Host gitlab.wtf.notworking
    User kbacon@email.com
    Hostname gitlab.wtf.notworking
    IdentityFile ~/.ssh/company_gitlab # path to private key
    AddKeysToAgent yes

With this .gitconfig:
.gitconfig

[user]
        name = kbacon
        email = kbacon@email.com
insteadof = https://gitlab.wtf.notworking/

The go get command then requests my password, but it is supposed to be using ssh. Why is it asking for my password?

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
git@gitlab.wtf.notworking's password:

答案1

得分: 1

如果你正在使用带有/而不是:的SSH URL,你的.gitconfig应该是这样的:

insteadof = https://gitlab.wtf.notworking/

使用:的方式是这样的:

insteadof = https://gitlab.wtf.notworking/

在你的ssh配置文件中,确保使用服务账户git,而不是你的登录账户,同时指定端口和自定义的主机条目:

Host gitlab-wtf
    User git
    Hostname gitlab.wtf.notworking
    IdentityFile ~/.ssh/company_gitlab # 私钥路径
    AddKeysToAgent yes
    Port 2224

这样,你可以使用:

insteadof = https://gitlab.wtf.notworking/

不再需要git@或者:2224了。

英文:

If you are using an SSH URL with / instead of :, your .gitconfig should be:

insteadof = https://gitlab.wtf.notworking/

With ":"

insteadof = https://gitlab.wtf.notworking/

In your ssh config file, make sure to use the service account git, not your login, with the port, and a custom Host entry:

Host gitlab-wtf
    User git
    Hostname gitlab.wtf.notworking
    IdentityFile ~/.ssh/company_gitlab # path to private key
    AddKeysToAgent yes
    Port 2224

That way, you can use:

insteadof = https://gitlab.wtf.notworking/

No more git@ or :2224.

答案2

得分: -2

看起来在.gitconfig文件中缺少端口号。

更新:我看到如果你添加了端口号,你会得到一个不同的错误,但显然需要端口号,因为你正在非标准端口上运行ssh。

英文:

Looks like port number is missing in .gitconfig

UPD: I see if you add it you get a different error, but clearly port number IS needed as you're running ssh on non-standard port.

huangapple
  • 本文由 发表于 2023年1月10日 05:44:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75063245.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定