Maison  >  Article  >  développement back-end  >  Importer le projet Go depuis le référentiel privé Gilab à l'aide de ssh : révision inconnue

Importer le projet Go depuis le référentiel privé Gilab à l'aide de ssh : révision inconnue

WBOY
WBOYavant
2024-02-09 11:24:08980parcourir

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

l'éditeur php Xigua vous présentera comment utiliser SSH pour importer une révision inconnue d'un projet Go à partir d'un référentiel GitLab privé. La connexion à GitLab via SSH vous permet d'importer facilement des projets dans votre environnement local pour les modifier et les développer. Cet article expliquera en détail chaque étape du processus d'importation afin que les lecteurs puissent terminer l'opération facilement. Avant de continuer, assurez-vous que Git and Go est installé et que vous avez créé un référentiel privé sur GitLab. commençons!

Contenu de la question

J'essaie d'importer un projet go à partir d'un référentiel gitlab privé et auto-hébergé en utilisant ssh. Lorsque j'essaie de faire cela, j'obtiens l'erreur suivante.

Sortie

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/

Aller au fichier mod

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

dépôt gitlab

Le dépôt gitlab a un projet avec une balise release v1.0.0

L'adresse que j'avais utilisée pour cloner

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

fichier de configuration ssh

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

Utilisez ce .gitconfig : .gitconfig

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

Ensuite, la commande go get me demandera mon mot de passe, mais elle doit utiliser ssh. Pourquoi me demande-t-on mon mot de passe ?

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:

Solution de contournement

Si vous utilisez ssh, l'URL est / 而不是 :,您的 .gitconfig elle devrait être :

[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/

Utilisez ":"

[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/

Dans votre fichier de configuration ssh, assurez-vous d'utiliser le compte de service git et non vos entrées de connexion, de port et d'hôte personnalisé :

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

De cette façon, vous pouvez utiliser :

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

Pas plus git@:2224.

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Cet article est reproduit dans:. en cas de violation, veuillez contacter admin@php.cn Supprimer