Gerrit 服務器入門使用-項目的創建與克隆
作者:尹正傑
版權聲明:原創作品,謝絕轉載!否則將追究法律責任。
一.創建克隆項目
1>.點擊"BROWSE"
2>.點擊"CREATE NEW"
3>.項目創建成功
二.基於HTTP方式克隆項目
1>.克隆項目
[gerrit@node201.yinzhengjie.org.cn ~]$ [gerrit@node201.yinzhengjie.org.cn ~]$ ll total 0 drwxrwxr-x 14 gerrit gerrit 176 Jun 17 09:06 soft [gerrit@node201.yinzhengjie.org.cn ~]$ [gerrit@node201.yinzhengjie.org.cn ~]$ [gerrit@node201.yinzhengjie.org.cn ~]$ git clone "http://172.30.1.201:8080/yinzhengjie-code" Cloning into 'yinzhengjie-code'... remote: Counting objects: 2, done remote: Finding sources: 100% (2/2) remote: Total 2 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (2/2), done. [gerrit@node201.yinzhengjie.org.cn ~]$ [gerrit@node201.yinzhengjie.org.cn ~]$ ll total 0 drwxrwxr-x 14 gerrit gerrit 176 Jun 17 09:06 soft drwxrwxr-x 3 gerrit gerrit 18 Jun 18 08:30 yinzhengjie-code [gerrit@node201.yinzhengjie.org.cn ~]$ [gerrit@node201.yinzhengjie.org.cn ~]$ ll yinzhengjie-code/ total 0 [gerrit@node201.yinzhengjie.org.cn ~]$ [gerrit@node201.yinzhengjie.org.cn ~]$
2>.查看Gerrit的用戶名
3>.在git上配置和Gerrit上存在的用戶名和郵箱(要進入到已經克隆的項目中)
[gerrit@node201.yinzhengjie.org.cn ~]$ ll total 0 drwxrwxr-x 14 gerrit gerrit 176 Jun 17 09:06 soft drwxrwxr-x 3 gerrit gerrit 18 Jun 18 08:30 yinzhengjie-code [gerrit@node201.yinzhengjie.org.cn ~]$ cd yinzhengjie-code/ [gerrit@node201.yinzhengjie.org.cn ~/yinzhengjie-code]$ [gerrit@node201.yinzhengjie.org.cn ~/yinzhengjie-code]$ git config user.name "jason" [gerrit@node201.yinzhengjie.org.cn ~/yinzhengjie-code]$ [gerrit@node201.yinzhengjie.org.cn ~/yinzhengjie-code]$ git config user.email "y1053419035@qq.com" [gerrit@node201.yinzhengjie.org.cn ~/yinzhengjie-code]$
4>.下載commit-msg
[gerrit@node201.yinzhengjie.org.cn ~/yinzhengjie-code]$ curl -Lo .git/hooks/commit-msg http://172.30.1.201:8080/tools/hooks/commit-msg % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 4781 100 4781 0 0 2119k 0 --:--:-- --:--:-- --:--:-- 2334k [gerrit@node201.yinzhengjie.org.cn ~/yinzhengjie-code]$
三.通過ssh方式克隆項目
1>.創建密鑰
[root@node203.yinzhengjie.org.cn ~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa Generating public/private rsa key pair. Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:jjm9d783Ac7qfftXmgCPRmI6fJ/5yf74YHZSi4ofw7I root@node203.yinzhengjie.org.cn The key's randomart image is: +---[RSA 2048]----+ | | | | | | | o o . | | . oSo +o o | | +=..o o= o.| | +o+o+oB.ooo| | . ==Oo*ooo| | Eo+=*=*+*| +----[SHA256]-----+ [root@node203.yinzhengjie.org.cn ~]#
2>.點擊設置
3>.點擊“SSH Keys”
4>.點擊"SSH keys",將公鑰拷貝到Gerrit上后點擊"ADD NEW SSH KEY"
5>.公鑰添加成功
6>.查看ssh的克隆命令
7>.使用ssh的方式克隆代碼
[root@node203.yinzhengjie.org.cn ~]# ll total 0 [root@node203.yinzhengjie.org.cn ~]# [root@node203.yinzhengjie.org.cn ~]# git clone "ssh://jason@node201.yinzhengjie.org.cn:29418/yinzhengjie-code" Cloning into 'yinzhengjie-code'... The authenticity of host '[node201.yinzhengjie.org.cn]:29418 ([172.30.1.201]:29418)' can't be established. ECDSA key fingerprint is SHA256:Mx8JcnxxxM/b99YiBG6+S8JP8Q12GNFYz0g/0+YO4c0. ECDSA key fingerprint is MD5:c0:2a:ae:84:31:99:7b:fb:80:b3:e8:a5:d9:42:75:6a. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[node201.yinzhengjie.org.cn]:29418,[172.30.1.201]:29418' (ECDSA) to the list of known hosts. remote: Counting objects: 2, done remote: Finding sources: 100% (2/2) remote: Total 2 (delta 0), reused 0 (delta 0) Receiving objects: 100% (2/2), done. [root@node203.yinzhengjie.org.cn ~]# [root@node203.yinzhengjie.org.cn ~]# ll total 0 drwxr-xr-x 3 root root 18 Jun 19 00:03 yinzhengjie-code [root@node203.yinzhengjie.org.cn ~]# [root@node203.yinzhengjie.org.cn ~]# ll yinzhengjie-code/ total 0 [root@node203.yinzhengjie.org.cn ~]# [root@node203.yinzhengjie.org.cn ~]#
8>.使用另一種方式進行克隆
[root@node203.yinzhengjie.org.cn ~]# ssh -p 29418 jason@172.30.1.201 **** Welcome to Gerrit Code Review **** Hi jason, you have successfully connected over SSH. Unfortunately, interactive shells are disabled. To clone a hosted Git repository, use: git clone ssh://jason@node201.yinzhengjie.org.cn:29418/REPOSITORY_NAME.git #我們根據提示,這種克隆方式也是ok的 Connection to 172.30.1.201 closed. [root@node203.yinzhengjie.org.cn ~]#