建立repo服務器三(gerrit 建立項目)

參考:https://blog.csdn.net/zbc415766331/article/details/82663291

https://www.jianshu.com/p/eccdf6a032bf

一、新建一個空的項目:

 

新建一個項目test1

在另一臺客戶端機器上,使用git clone "ssh://[email protected]:29418/test1" 可以將代碼下載到本地

git push成功,但是這個是直接提交到git倉庫了,沒有經過gerrit

#git push
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 263 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Processing changes: refs: 1, done    
To ssh://[email protected]:29418/test1
   be31ebf..d6a3037  master -> master

 

vi test2.c

git commit -a -m "modefy test2.c"

這次不要直接提交,使用git push origin HEAD:refs/for/master測試

#git push origin HEAD:refs/for/master
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 269 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Processing changes: refs: 1, done    
remote: ERROR: commit 9addd69: missing Change-Id in message footer
remote: 
remote: Hint: to automatically insert a Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29418 [email protected]:hooks/commit-msg ${gitdir}/hooks/
remote: and then amend the commit:
remote:   git commit --amend --no-edit
remote: Finally, push your changes again
remote: 
To ssh://[email protected]:29418/test1
 ! [remote rejected] HEAD -> refs/for/master (commit 9addd69: missing Change-Id in message footer)
error: failed to push some refs to 'ssh://[email protected]:29418/test1'

原因是沒有把change-Id加入到message,可以通過git log查看

參考:https://www.cnblogs.com/zndxall/p/9603834.html

根據提示覆制鉤子文件過來,

#gitdir=$(git rev-parse --git-dir); scp -p -P 29418 [email protected]:hooks/commit-msg ${gitdir}/hooks/

或者scp -p -P 29418 [email protected]:hooks/commit-msg .git/hooks/(相等的)

#git commit --amend --no-edit
git: 'interpret-trailers' is not a git command. See 'git --help'.
cannot insert change-id line in .git/COMMIT_EDITMSG

#git commit --amend

依然會打印

git: 'interpret-trailers' is not a git command. See 'git --help'.
cannot insert change-id line in .git/COMMIT_EDITMSG

原因是git版本太舊了或gerrit版本太高了,git version 1.7.9.5,Gerrit Code Review 3.1.0不匹配

2個解決辦法:

1、拷貝低版本的gerrit的commit-msg文件過來覆蓋掉,如拷貝Gerrit Code Review 2.14.6的commit-msg過來,重新提交成功

#git commit --amend --no-edit
[master 61a472d] 1
 1 file changed, 1 insertion(+)

2、升級客戶端的git版本,參考:https://blog.csdn.net/qq_34706266/article/details/92806540

在ubuntu12.04上默認安裝了git:

git version

git version 1.7.9.5

sudo add-apt-repository ppa:git-core/ppa

sudo apt-get update
sudo apt-get install git

安裝完成後,再查看git版本:
git  version

git version 2.19.2

使用git log查看發現有change-Id了

 git log
commit d21ab56c7eeffc42b9741528d792eb91c0a5cc01
Author: xiangzi10 <[email protected]>
Date:   Fri Dec 20 11:53:38 2019 +0800

    edit test1.c
    
    Change-Id: If00ec690d2a0566db14d1a8b37286a311a033e69

commit 9addd694a33ceca1d50a9bb85e140c30444683d3
Author: xiangzi10 <[email protected]>
Date:   Fri Dec 20 09:24:23 2019 +0800

    modefy test2.c

commit d6a30374a1175ea73a3c363c5f612885339fc13f
Author: xiangzi10 <[email protected]>
Date:   Thu Dec 19 16:54:13 2019 +0800

    add test2.c

commit be31ebf1b464d95f079e2cfaed97f99509ff192b
Author: xiangzi10 <[email protected]>
Date:   Thu Dec 19 15:12:37 2019 +0800

    add test1.c

commit 3123b4035d8cc48356f116173400552e9a82b109
Author: git <[email protected]>
Date:   Thu Dec 19 13:41:40 2019 +0800

    Initial empty repository
#git push origin HEAD:refs/for/master
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 324 bytes, 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.0.198:8081/c/test1/+/1 edit test1.c [NEW]
remote: 
To ssh://[email protected]:29418/test1
 * [new branch]      HEAD -> refs/for/master

再次push成功,git push origin HEAD:refs/for/master

注意CR欄沒有勾,點擊replay+2.提交,成功。

 

總結:

1、不使用repo,單獨clone一個項目,可以使用:

git clone "ssh://xxx@xxx:29418/xxx"&&scp -p -P 29418 xxx@xxx:hooks/commit-msg "xxx/.git/hooks/"

 

二、推送一個已存在的項目

新建一個項目,gerrit_tset,後查看gerrit倉庫,發現多了個gerrit_test.git

在客戶端另一臺機器上創建個空目錄gerrit,git ini新建個空倉庫。

 #git push ssh://[email protected]:29418/gerrit_test.git *:*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
85:0f:39:fc:35:94:a3:87:b2:1d:58:67:ea:e4:e6:97.
Please contact your system administrator.
Add correct host key in /home/xxx/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/xxx/.ssh/known_hosts:7
  remove with: ssh-keygen -f "/home/xxx/.ssh/known_hosts" -R [192.168.111.198]:29418
ECDSA host key for [192.168.111.198]:29418 has changed and you have requested strict checking.
Host key verification failed.
fatal: The remote end hung up unexpectedly

解決辦法:ssh-keygen -f "/home/xxx/.ssh/known_hosts" -R [192.168.111.198]:29418

 ssh-keygen -f "/home/xxx/.ssh/known_hosts" -R [192.168.111.198]:29418
/home/xxx/.ssh/known_hosts updated.
Original contents retained as /home/xxx/.ssh/known_hosts.old

#git push ssh://[email protected]:29418/gerrit_test.git *:*
The authenticity of host '[192.168.111.198]:29418 ([192.168.111.198]:29418)' can't be established.
ECDSA key fingerprint is 85:0f:39:fc:35:94:a3:87:b2:1d:58:67:ea:e4:e6:97.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.111.198]:29418' (ECDSA) to the list of known hosts.
Everything up-to-date

成功上傳空項目

在客戶端項目,

Q1:

#git push ssh://[email protected]:29418/MSD6A358/MSD6A358.git *:*
The authenticity of host '[192.168.111.198]:29418 ([192.168.111.198]:29418)' can't be established.
ECDSA key fingerprint is a2:02:af:1d:59:89:7a:b4:9a:85:9b:3a:00:22:3e:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.111.198]:29418' (ECDSA) to the list of known hosts.
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

登錄gerrit網頁,http://192.168.111.198:8081

 

將本機的ssh key添加進去

重新上傳:

# git push ssh://[email protected]:29418/MSD6A358/MSD6A358.git HEAD:refs/heads/master
To ssh://[email protected]:29418/MSD6A358/MSD6A358.git
 ! [rejected]        HEAD -> master (non-fast-forward)
error: failed to push some refs to 'ssh://[email protected]:29418/MSD6A358/MSD6A358.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

因爲和倉庫裏原有的衝突吧

在服務器上~/review_site/git$ rm -rf MSD6A358/

#bin/gerrit.sh restart

#ssh -p 29418 [email protected] gerrit create-project MSD6A358/MSD6A358.git

成功

#git push ssh://[email protected]:29418/MSD6A358/MSD6A358.git HEAD:refs/heads/master
Counting objects: 488181, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (449762/449762), done.
Writing objects: 100% (488181/488181), 9.73 GiB | 3.08 MiB/s, done.
Total 488181 (delta 127744), reused 0 (delta 0)
error: unpack failed: error Java heap space44)   
fatal: Unpack error, check server log
To ssh://[email protected]:29418/MSD6A358/MSD6A358.git
 ! [remote rejected] HEAD -> master (n/a (unpacker error))
error: failed to push some refs to 'ssh://[email protected]:29418/MSD6A358/MSD6A358.git'

可能是commit 衝突

查看error_log

[2019-12-20 16:29:05,798] [SSH git-receive-pack /MSD6A358/MSD6A358_AN6.0_20190821.git (git)] ERROR com.google.gerrit.sshd.BaseCommand : Internal server error (user git account 1000000) during git-receive-pack '/MSD6A358/MSD6A358_AN6.0_20190821.git'
com.google.gerrit.sshd.BaseCommand$Failure: fatal: Unpack error, check server log
        at com.google.gerrit.sshd.commands.Receive.runImpl(Receive.java:129)
        at com.google.gerrit.sshd.AbstractGitCommand.service(AbstractGitCommand.java:107)
        at com.google.gerrit.sshd.AbstractGitCommand.access$000(AbstractGitCommand.java:32)
        at com.google.gerrit.sshd.AbstractGitCommand$1.run(AbstractGitCommand.java:72)
        at com.google.gerrit.sshd.BaseCommand$TaskThunk.run(BaseCommand.java:465)
        at com.google.gerrit.server.logging.LoggingContextAwareRunnable.run(LoggingContextAwareRunnable.java:110)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at com.google.gerrit.server.git.WorkQueue$Task.run(WorkQueue.java:610)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: Unpack error on project "MSD6A358/MSD6A358_AN6.0_20190821":
  AdvertiseRefsHook: org.eclipse.jgit.transport.AdvertiseRefsHookChain@1bc2fb3dclass org.eclipse.jgit.transport.AdvertiseRefsHookChain

        at com.google.gerrit.sshd.commands.Receive.runImpl(Receive.java:128)
        ... 13 more
Caused by: org.eclipse.jgit.errors.UnpackException: Exception while parsing pack stream
        at org.eclipse.jgit.transport.ReceivePack.service(ReceivePack.java:2233)
        at org.eclipse.jgit.transport.ReceivePack.receive(ReceivePack.java:2158)
        at com.google.gerrit.sshd.commands.Receive.runImpl(Receive.java:99)
        ... 13 more
Caused by: java.lang.OutOfMemoryError: Java heap space
        at org.eclipse.jgit.internal.storage.pack.BinaryDelta.apply(BinaryDelta.java:163)
        at org.eclipse.jgit.internal.storage.pack.BinaryDelta.apply(BinaryDelta.java:118)
        at org.eclipse.jgit.transport.PackParser.resolveDeltas(PackParser.java:697)
        at org.eclipse.jgit.transport.PackParser.resolveDeltas(PackParser.java:673)
        at org.eclipse.jgit.transport.PackParser.resolveDeltas(PackParser.java:636)
        at org.eclipse.jgit.transport.PackParser.processDeltas(PackParser.java:613)
        at org.eclipse.jgit.transport.PackParser.parse(PackParser.java:584)
        at org.eclipse.jgit.internal.storage.file.ObjectDirectoryPackParser.parse(ObjectDirectoryPackParser.java:201)
        at org.eclipse.jgit.transport.ReceivePack.receivePack(ReceivePack.java:1502)
        at org.eclipse.jgit.transport.ReceivePack.receivePackAndCheckConnectivity(ReceivePack.java:1215)
        at org.eclipse.jgit.transport.ReceivePack.service(ReceivePack.java:2181)
        ... 15 more

原因是push的內容太大,超出jvm的空間。不太好解決,可以換個思路。

先將已有的項目scp到服務器gerrit倉庫,然後建立連接即可:

#scp -r MSD6A358.git [email protected]:/home/git/repositories/MSD6A358/:注意這裏scp的是裸倉庫

#git config --list看下已有項目的配置

#git remote -v
origin  xxx@xxx:xxx.git (fetch)
origin  xxx@xxx:xxx.git (push)

#git remote rm origin     刪除原來的連接

#git remote add origin ssh://[email protected]:29418/MSD6A358/MSD6A358      建立新連接

#git pull --rebase origin master

#scp -p -P 29418 [email protected]:hooks/commit-msg ".git/hooks/"

#git commit --amend

#git push origin HEAD:refs/for/master

成功

 

中間嘗試:

#git push ssh://[email protected]:29418/MSD6A358/MSD6A358.git HEAD:refs/for/master
Total 0 (delta 0), reused 0 (delta 0)
remote: Processing changes: refs: 1, done    
To ssh://192.168.0.198:29418/MSD6A358/MSD6A358.git
 ! [remote rejected] HEAD -> refs/for/master (no new changes)
error: failed to push some refs to 'ssh://[email protected]:29418/MSD6A358/MSD6A358.git'

#git config [email protected]:/home/git/repositories/MSD6A358/MSD6A358_AN6.0_20190821.git

失敗

#git push [email protected]:29418/MSD6A358/MSD6A358.git HEAD:refs/for/master
The authenticity of host '192.168.0.198 (192.168.0.198)' can't be established.
ECDSA key fingerprint is 10:ca:ab:5f:c9:1a:4f:21:a9:45:2c:a8:c6:0a:19:9f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.198' (ECDSA) to the list of known hosts.
FATAL: W any 29418/MSD6A358/MSD6A358 202 DENIED by fallthru
(or you mis-spelled the reponame)
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

失敗

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章