1 - 簡介
雖然Gerrit 本身提供 Code Review和 Git 倉庫的兩大功能,但實際上很多項目用的是其他的Git倉庫,例如GitLab和GitHub。
一般情況下,Gerrit位於最終代碼庫的前面一層,用於代碼的人工審核和對CI任務的觸發進行驗證。
這里以GitLab為例
Gerrit和GitLab集成后,在Gerrit上的項目倉庫有變化時,會自動同步到GitLab上對應的項目倉庫中。
但Gerrit和GitLab的同步只能是單向同步(Gerrit--》GitLab),也就是說直接在GitLab上項目倉庫的變動不會自動同步到Gerrit上。
因此建議在Gerrit和GitLab集成后,所有的操作都在Gerrit上完成。
Replication插件
如果想要將Gerrit上的改動自動同步到GitLab上,就需要用到Gerrit的Replication插件。
Replication 插件可以同時對接已有的 Git 倉庫系統,通常用於提供 changes 的鏡像或者熱備份,自動地將 Gerrit Code Review創建的任何改動 push 到另外一個系統里。
2 - 權限配置
2.1 配置Gerrit訪問GitLab
將Gerrit的公鑰添加到GitLab的管理員賬號后,Gerrit服務可以通過SSH拉取GitLab上任意項目的代碼。
特別注意:gerrit用戶和root用戶的公鑰都要添加!
[gerrit@mt101 ~]$ pwd
/home/gerrit
[gerrit@mt101 ~]$ whoami
gerrit
[gerrit@mt101 ~]$ pwd
/home/gerrit
[gerrit@mt101 ~]$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCE36kKv9cRTR/UU+7c620a6sYwptzVCRa8KBWBVijXNME+te4Nt2ZKp1uVvVOYKWv4akR/E5wMMTa9sYiE7EZJsC0cfg+FSuvc7WeoyT0hWYEWAabqp1cAApZUKSm7c06829dSTAPLj4MIEQOtEzID8iaq7+kGDf6RsGF6QRrAVx28k5ZJNvNFLpFqv4cjOaDbWOKaVXkrAgYYdLWWJ6xEeQTJ6yxCkk9KY7+rHEHd9zEoJYiA03J9UgxRRkyTX8vRW39RHVVM+GriOasAgwhvhFZXJsm6mJVXr2Y3AFcMNPo4YJNq68LGdU8bjqN78ysBbkxfIDq+r3ANc7+D+Az sshtest
[gerrit@mt101 ~]$
[gerrit@mt101 ~]$ su - root
Password:
Last login: Fri Dec 13 23:15:07 CST 2019 on pts/0
ABRT has detected 1 problem(s). For more info run: abrt-cli list --since 1576224692
[root@mt101 ~]#
[root@mt101 ~]# pwd
/root
[root@mt101 ~]# whoami
root
[root@mt101 ~]# ll .ssh
total 8
-rw------- 1 root root 1679 Dec 11 23:10 id_rsa
-rw-r--r-- 1 root root 392 Dec 11 23:10 id_rsa.pub
[root@mt101 ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDkUOVXJ49OolxX34Lh/qlLmdEtYbPWlELx/Kxk6EWfmuGI6eYYVIOSE4b43nEXP0T0DM8j0jat75dZ4Zc+Z21PVplJ4uUuruBV/JMfOzx2vUD2zAFELq0TX4IMRJpPjYrk6asx1KYQUr/lQIxgqUbFsTDFWmIM186kcl4Q2daU8hznfP7pJBu4DAowxVPP+OsnhT93jq8IIwUFnaUBDUh5Fr/T56b0hOljUWFAIImB5j+SsYg5airaJK44AhuoeOnrUAQEApsdqOtRdyFdwpYgQVvN61WQKJlBOwmV8lGGUZeuvYmPeSf0VzUUPmhGIgtwyeTrr7I1TcpncffAILy/ root@mt101
[root@mt101 ~]#
[root@mt101 ~]# exit
logout
[gerrit@mt101 ~]$
root賬戶登錄GitLab:Settings---》SSH Keys---》添加並保存。
2.2 配置GitLab訪問Gerrit
GitLab:192.168.16.102
[root@mt102 ~]# pwd
/root
[root@mt102 ~]# whoami
root
[root@mt102 ~]# ll .ssh
total 8
-rw------- 1 root root 1679 Dec 11 15:37 id_rsa
-rw-r--r-- 1 root root 392 Dec 11 15:37 id_rsa.pub
[root@mt102 ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDGiLcDnAaj2gOemJKcnlGnGmy0cb9N2uaqyuzWdPZai+blPq7Mqt4DICnRKeU0MAoeEuSM8ST01zItwrTlsPZNMKEjJ60PqAohWhHHtJuHu0sl6fs2gdrgtGtjBeqRJ9C4iRTlD3PWCqzA9M7+vZhfPzKm3QffOacTpA6k00GSep2yIpko7vcwE7YwclulaSi+RQtwxBoJVK1x3vOrCVN0y4rK4RzbO0rLYByWDARZrzCjmh5Cfjs8vs4VyYAA0t5rDEcnU/mTSjBLT79Mhlzr9b9zpT21FkDphcatJoLbMLVEo02HYs3RzxWp+mtbrwt1hCMHcOdJ328UiA0JiDX1 root@mt102
[root@mt102 ~]#
[root@mt102 ~]#
[root@mt102 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.16.101
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.16.101 (192.168.16.101)' can't be established.
ECDSA key fingerprint is SHA256:oShRek8kc5ZO9vmSnwSPuWxKieGfPuTG8VorbWM6CiE.
ECDSA key fingerprint is MD5:94:44:a1:ea:8c:c9:2b:fd:85:5e:a5:78:2d:1e:b4:53.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.16.101's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.16.101'"
and check to make sure that only the key(s) you wanted were added.
[root@mt102 ~]#
[root@mt102 ~]# ssh 192.168.16.101
Last login: Fri Dec 13 23:20:42 2019
[root@mt101 ~]# exit
logout
Connection to 192.168.16.101 closed.
[root@mt102 ~]#
[root@mt102 ~]# ll .ssh
total 12
-rw------- 1 root root 1679 Dec 11 15:37 id_rsa
-rw-r--r-- 1 root root 392 Dec 11 15:37 id_rsa.pub
-rw-r--r-- 1 root root 176 Dec 13 23:27 known_hosts
[root@mt102 ~]#
[root@mt102 ~]# cat .ssh/known_hosts
192.168.16.101 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMtkxCPeK5boH0UWlpVYqNv3fIqsZSTj+9iW1l6XV6QHavtFg3QPpB37hAd3PIRPdOzIvwEoTWvk3vks2vzTPMI=
[root@mt102 ~]#
Gerrit:192.168.16.101
[gerrit@mt101 ~]$
[gerrit@mt101 ~]$ su - root
Password:
Last login: Fri Dec 13 23:27:49 CST 2019 from 192.168.16.102 on pts/1
[root@mt101 ~]#
[root@mt101 ~]# ll .ssh
total 12
-rw------- 1 root root 392 Dec 13 23:27 authorized_keys
-rw------- 1 root root 1679 Dec 11 23:10 id_rsa
-rw-r--r-- 1 root root 392 Dec 11 23:10 id_rsa.pub
[root@mt101 ~]#
[root@mt101 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.16.102
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.16.102 (192.168.16.102)' can't be established.
ECDSA key fingerprint is SHA256:oShRek8kc5ZO9vmSnwSPuWxKieGfPuTG8VorbWM6CiE.
ECDSA key fingerprint is MD5:94:44:a1:ea:8c:c9:2b:fd:85:5e:a5:78:2d:1e:b4:53.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.16.102's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.16.102'"
and check to make sure that only the key(s) you wanted were added.
[root@mt101 ~]#
[root@mt101 ~]# ssh 192.168.16.102
Last login: Fri Dec 13 23:12:23 2019
[root@mt102 ~]# exit
logout
Connection to 192.168.16.102 closed.
[root@mt101 ~]#
[root@mt101 ~]# ll .ssh/
total 16
-rw------- 1 root root 392 Dec 13 23:27 authorized_keys
-rw------- 1 root root 1679 Dec 11 23:10 id_rsa
-rw-r--r-- 1 root root 392 Dec 11 23:10 id_rsa.pub
-rw-r--r-- 1 root root 176 Dec 13 23:31 known_hosts
[root@mt101 ~]#
[root@mt101 ~]# cat .ssh/known_hosts
192.168.16.102 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMtkxCPeK5boH0UWlpVYqNv3fIqsZSTj+9iW1l6XV6QHavtFg3QPpB37hAd3PIRPdOzIvwEoTWvk3vks2vzTPMI=
[root@mt101 ~]#
在Gerrit服務器上編輯用戶同步Gitlab的配置文件,需要手動創建
[gerrit@mt101 ~]$ cd gerrit_testsite/etc/
[gerrit@mt101 etc]$ pwd
/home/gerrit/gerrit_testsite/etc
[gerrit@mt101 etc]$
[gerrit@mt101 etc]$ vim .ssh/config
[gerrit@mt101 etc]$ cat .ssh/config
Host 192.168.16.102
IdentityFile ~/.ssh/id_rsa
PreferredAuthentications publickey
[gerrit@mt101 etc]$
[gerrit@mt101 etc]$ ll .ssh/config
-rw------- 1 gerrit gerrit 86 Dec 13 23:37 .ssh/config
[gerrit@mt101 etc]$
3 - 更新Gerrit配置文件
在Gerrit配置文件中添加關於的設置。
replication插件用於實現Gerrit和遠程代碼倉庫的自動同步。
[plugins]
allowRemoteAdmin = true
添加並重啟Gerrit服務
[gerrit@mt101 ~]$ sudo vim gerrit_testsite/etc/gerrit.config
[gerrit@mt101 ~]$ sudo cat gerrit_testsite/etc/gerrit.config
[gerrit]
basePath = git
canonicalWebUrl = http://192.168.16.101:8083/
serverId = 0b911b9e-195a-46b0-a5cd-b407b776b344
[container]
javaOptions = "-Dflogger.backend_factory=com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance"
javaOptions = "-Dflogger.logging_context=com.google.gerrit.server.logging.LoggingContext#getInstance"
user = root
javaHome = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64/jre
[index]
type = lucene
[auth]
type = HTTP
[receive]
enableSignedPush = false
[sendemail]
smtpServer = localhost
[sshd]
listenAddress = *:29418
[httpd]
listenUrl = http://192.168.16.101:8083/
[cache]
directory = cache
[gitweb]
type = gitweb
cgi = /var/www/git/gitweb.cgi
[plugins]
allowRemoteAdmin = true
[gerrit@mt101 ~]$
[gerrit@mt101 ~]$ sudo sh gerrit_testsite/bin/gerrit.sh restart
Stopping Gerrit Code Review: OK
Starting Gerrit Code Review: OK
[gerrit@mt101 ~]$
4 - 在Gerrit中創建項目
4.1 在GitLab中創建一個項目
- 關閉Auto DevOps:Settings---》CI/CD---》Auto DevOps,去除勾選---》Save changes
- 添加ReadMe文件
git@192.168.16.102:root/testrepo.git
4.2 在Gerrit創建一個空項目並同步GitLab
項目名與GitLab項目相同
- 刪除自動創建的目錄:sudo rm -rf testrepo.git/
- 重新從GitLab復制:git clone --bare git@192.168.16.102:root/testrepo.git
[gerrit@mt101 git]$ pwd
/home/gerrit/gerrit_testsite/git
[gerrit@mt101 git]$
[gerrit@mt101 git]$ ll
total 0
drwxr-xr-x 7 gerrit gerrit 119 Dec 10 14:43 All-Projects.git
drwxr-xr-x 7 gerrit gerrit 119 Dec 11 12:26 All-Users.git
drwxr-xr-x 7 root root 100 Dec 12 14:57 testrepo.git
[gerrit@mt101 git]$
[gerrit@mt101 git]$ sudo rm -rf testrepo.git/
[gerrit@mt101 git]$
[gerrit@mt101 git]$ git clone --bare git@192.168.16.102:root/testrepo.git
Cloning into bare repository 'testrepo.git'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.
[gerrit@mt101 git]$
[gerrit@mt101 git]$ ll
total 0
drwxr-xr-x 7 gerrit gerrit 119 Dec 10 14:43 All-Projects.git
drwxr-xr-x 7 gerrit gerrit 119 Dec 11 12:26 All-Users.git
drwxrwxr-x 7 gerrit gerrit 138 Dec 12 15:04 testrepo.git
[gerrit@mt101 git]$
[gerrit@mt101 git]$ ll testrepo.git/
total 16
drwxrwxr-x 2 gerrit gerrit 6 Dec 12 15:04 branches
-rw-rw-r-- 1 gerrit gerrit 128 Dec 12 15:04 config
-rw-rw-r-- 1 gerrit gerrit 73 Dec 12 15:04 description
-rw-rw-r-- 1 gerrit gerrit 23 Dec 12 15:04 HEAD
drwxrwxr-x 2 gerrit gerrit 242 Dec 12 15:04 hooks
drwxrwxr-x 2 gerrit gerrit 21 Dec 12 15:04 info
drwxrwxr-x 4 gerrit gerrit 30 Dec 12 15:04 objects
-rw-rw-r-- 1 gerrit gerrit 98 Dec 12 15:04 packed-refs
drwxrwxr-x 4 gerrit gerrit 31 Dec 12 15:04 refs
[gerrit@mt101 git]$
[gerrit@mt101 git]$ cat testrepo.git/config
[core]
repositoryformatversion = 0
filemode = true
bare = true
[remote "origin"]
url = git@192.168.16.102:root/testrepo.git
[gerrit@mt101 git]$
5 - 配置Grerrit與GitLab的同步
5.1 replication插件
通過Gerrit的replication插件來實現。
確認插件狀態:已安裝、已啟用。
[gerrit@mt101 git]$ ssh -p 29418 admin@192.168.16.101 gerrit plugin ls |grep replication
replication v3.1.0 ENABLED replication.jar
[gerrit@mt101 git]$
5.2 配置插件
在/home/gerrit/gerrit_testsite/etc
目錄下創建replication.config文件用於代碼同步。
特別注意:以后每創建一個新的項目,都要在該配置文件中添加對應的配置。
[gerrit@mt101 etc]$ pwd
/home/gerrit/gerrit_testsite/etc
[gerrit@mt101 etc]$
[gerrit@mt101 etc]$ vim replication.config
[gerrit@mt101 etc]$
[gerrit@mt101 etc]$ cat replication.config
[remote "testrepo"]
projects = testrepo
url = git@192.168.16.102:root/testrepo.git
push = +refs/heads/*:refs/heads/*
push = +refs/tags/*:refs/tags/*
push = +refs/changes/*:refs/changes/*
threads = 3
[gerrit@mt101 etc]$
[gerrit@mt101 etc]$ ssh -p 29418 admin@192.168.16.101 gerrit plugin reload replication
[gerrit@mt101 etc]$
6 - 本地代碼提交測試
6.1 本地設置
- 本地Git用戶配置要和Gerrit用戶信息一致
- 本地公鑰已添加到Gerrit用戶配置中
- 本地Git版本不能太低,否則會出現未知的錯誤
Anliven@Anliven-PC /d/Project/testrepo (master)
λ git config --global user.name "admin"
Anliven@Anliven-PC /d/Project/testrepo (master)
λ git config --global user.email "anliven@126.com"
Anliven@Anliven-PC /d/Project
λ git config --list |grep user
user.name=admin
user.email=anliven@126.com
Anliven@Anliven-PC /d/Project
λ
Anliven@Anliven-PC /d/Project
λ git --version
git version 2.19.0.windows.1
Anliven@Anliven-PC /d/Project
λ
Anliven@Anliven-PC /d/Project
λ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDQSFpwR9eBCTKfTbPEE8TWIo75KfX3AczpXK6nTKGH248pxjfq7cDe2cGj1VOSqknMqvg0g1LLiXrgbIGbtclt49UKSFXxWnVm04rZHVsz9rtfzxuF/NmSqSv7isYLZvwaI4aGXkLwILOemqwCbPRybGlkIiU9sgFK6m5gBWpsA6WqbHGlll8o1jC1cIuiPcJuYwod4+ehI5GvH3Tr3rUjkWy0QEhFfV22Nt79mJ3D+xDpDP/SxhPtPWw1Ob1+10+0+xvSTvGR/gcLUnUXciIooJVSypTPLnGe+d4Y5i+jCzDRIxeXBEQrQXafoxTjPNMb/T84mkPH+MSSTnvAk6Oelcs9MJLDIlXcDGSKXSzl2XmjjiTglq0R5gnRtUL6jxcyR0Db5mEF5maumfyKz58/O5pSDGVRW13O6V0YGq6j8f5mcn8h1usdqabbirUGA5+7OB2Ek4KlLy/U6GkHtr5gY4zch08A8/xWowGppOjb8b/MqxJuLmQY1+vvUlupALd6nNmacugmlZK+ZsheTCJhdNHLBVl40b4UZdbD19LCI5cFonvJP979J4SIc8gHh7SXu7lSTRWciA0BKLrwhhHID1PHnF5o0re4kENZW4LYiXhBo998+7TtXiK+itnjUsfHRDPUvQC0OrhmLf/DAyanpRs65rXFONEaVGf4NS+PCQ== anliven@126.com
Anliven@Anliven-PC /d/Project
λ
6.2 下拉代碼
這里使用了SSH方式下的Clone with commit-msg hook模式
Anliven@Anliven-PC /d/Project
λ pwd
/d/Project
Anliven@Anliven-PC /d/Project
λ ll
total 0
drwxr-xr-x 1 Anliven 197121 0 十一 28 00:05 testproject/
Anliven@Anliven-PC /d/Project
λ
Anliven@Anliven-PC /d/Project
λ ll
total 0
drwxr-xr-x 1 Anliven 197121 0 十一 28 00:05 testproject/
Anliven@Anliven-PC /d/Project
λ git clone "ssh://admin@192.168.16.101:29418/testrepo" && scp -p -P 29418 admin@192.168.16.101:hooks/commit-msg "testrepo/.git/hooks/"
Cloning into 'testrepo'...
remote: Counting objects: 12, done
remote: Finding sources: 100% (12/12)
remote: Total 12 (delta 0), reused 12 (delta 0)
Receiving objects: 100% (12/12), done.
commit-msg 100% 1790 297.0KB/s 00:00
Anliven@Anliven-PC /d/Project
λ
Anliven@Anliven-PC /d/Project
λ ll
total 0
drwxr-xr-x 1 Anliven 197121 0 十一 28 00:05 testproject/
drwxr-xr-x 1 Anliven 197121 0 十二 13 23:49 testrepo/
Anliven@Anliven-PC /d/Project
λ ll testrepo/
total 3
-rw-r--r-- 1 Anliven 197121 31 十二 13 23:49 README.md
-rw-r--r-- 1 Anliven 197121 41 十二 13 23:49 testlog.txt
-rw-r--r-- 1 Anliven 197121 9 十二 13 23:49 try.txt
Anliven@Anliven-PC /d/Project
λ
6.3 改動
Anliven@Anliven-PC /d/Project
λ cd testrepo/
Anliven@Anliven-PC /d/Project/testrepo (master)
λ echo "1234567890" >> testlog.txt
Anliven@Anliven-PC /d/Project/testrepo (master)
λ git add *
warning: LF will be replaced by CRLF in testlog.txt.
The file will have its original line endings in your working directory
Anliven@Anliven-PC /d/Project/testrepo (master)
λ git commit -m "update testlog"
[master 6c8f1d2] update testlog
1 file changed, 1 insertion(+)
Anliven@Anliven-PC /d/Project/testrepo (master)
λ
Anliven@Anliven-PC /d/Project/testrepo (master)
λ cat testlog.txt
This is the first change from local PC.
1234567890
Anliven@Anliven-PC /d/Project/testrepo (master)
λ
6.4 提交改動
特別注意:
提交的命令變為“git push -u origin HEAD:refs/for/
“refs/for/*”會將變更提交放到暫存區中,等待代碼審核和集成驗證
Anliven@Anliven-PC /d/Project/testrepo (master)
λ git push -u origin HEAD:refs/for/master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 387 bytes | 387.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Processing changes: refs: 1, new: 1, done
remote:
remote: SUCCESS
remote:
remote: http://192.168.16.101:8083/c/testrepo/+/61 update testlog [NEW]
remote:
To ssh://192.168.16.101:29418/testrepo
* [new branch] HEAD -> refs/for/master
Anliven@Anliven-PC /d/Project/testrepo (master)
λ
Anliven@Anliven-PC /d/Project/testrepo (master)
λ git log -1
commit 6c8f1d20f23697d1d677ac86c30120fdd7d20c43 (HEAD -> master)
Author: admin <anliven@126.com>
Date: Fri Dec 13 23:53:08 2019 +0800
update testlog
Change-Id: I3513942d2b6d2b951b3470946170eb706c4ab8d6
Anliven@Anliven-PC /d/Project/testrepo (master)
λ
6.5 在Gerrit查看提交的改動
在登錄界面的CHANGES欄目下可以看到提交的狀態(Open、Merged和Abandoned)
這里可以看到改動正處於Open狀態下。
點擊“first change”這個Subject,可以看到具體信息
6.6 在Gerrit進行人工審核
- 默認只有Project Owners和Administrator群組用戶擁有“Code-Review”選項+2的權限(提交通過)
- 普通用戶的“Code-Review”選項只能選擇+1(審核建議)
代碼審核無誤,點擊“Code-Review+2”按鈕
點擊“Summit”按鈕才能進入代碼庫
查看提交的最終狀態
如果提交成功,頁面History部分會出現“Change has been successfully merged”信息
點擊頁面中gitweb鏈接,可以直觀的看到相關具體信息
CHANGES下的Merged信息
6.7 在GitLab確認同步信息
在GitLab的Master分支確認代碼是否同步
6.8 Replication日志
可以從Replication日志獲取同步狀態信息。
[gerrit@mt101 ~]$ pwd
/home/gerrit
[gerrit@mt101 ~]$ ll gerrit_testsite/logs/replication_log
-rw-r--r-- 1 root root 1982 Dec 14 00:02 gerrit_testsite/logs/replication_log
[gerrit@mt101 ~]$
成功同步的日志
[2019-12-14 00:02:01,017] [c17c270d] Replication to git@192.168.16.102:root/testrepo.git started...
[2019-12-14 00:02:01,020] [c17c270d] Push to git@192.168.16.102:root/testrepo.git references: [RemoteRefUpdate[remoteName=refs/changes/61/61/meta, NOT_ATTEMPTED, (null)...6f1717ea24e438692c05ce9cb20255506e8167e6, srcRef=refs/changes/61/61/meta, forceUpdate, message=null], RemoteRefUpdate[remoteName=refs/heads/master, NOT_ATTEMPTED, (null)...6c8f1d20f23697d1d677ac86c30120fdd7d20c43, srcRef=refs/heads/master, forceUpdate, message=null]]
[2019-12-14 00:02:22,332] [c17c270d] Replication to git@192.168.16.102:root/testrepo.git completed in 21314ms, 15003ms delay, 0 retries
7 - 問題處理
7.1 問題1 - 執行git commit命令報錯
問題現象:執行git commit命令時報錯“git: 'interpret-trailers' is not a git command. See 'git --help'.”
[gerrit@mt101 testrepo]$ git commit -m "a new file"
git: 'interpret-trailers' is not a git command. See 'git --help'.
cannot insert change-id line in .git/COMMIT_EDITMSG
[gerrit@mt101 testrepo]$
[gerrit@mt101 testrepo]$ git --version
git version 1.8.3.1
[gerrit@mt101 testrepo]$
問題分析:Git版本版本太低導致。
處理方法:在不影響業務的情況下,升級git版本。
參考信息:https://blog.csdn.net/a10703060237/article/details/89704924
7.2 問題2:在本地執行“git clone”命令拉取代碼時報錯
問題現象:提示“Could not read from remote repository. ”
Anliven@Anliven-PC /d/Project
λ git clone "ssh://admin@192.168.16.101:29418/testrepo"
Cloning into 'testrepo'...
ssh: connect to host 192.168.16.101 port 29418: Connection timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
問題分析:經排查,確認防火牆未開放端口,網絡不通導致。
處理方法:防火牆開放端口,重新拉取代碼。
[gerrit@mt101 ~]$ sudo firewall-cmd --zone=public --permanent --add-port=29418/tcp
success
[gerrit@mt101 ~]$ sudo firewall-cmd --reload
success
[gerrit@mt101 ~]$