当前位置:   article > 正文

建立repo服务器三(gerrit 建立项目)_gerrit创建项目

gerrit创建项目

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

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

一、新建一个空的项目:

 

新建一个项目test1

在另一台客户端机器上,使用git clone "ssh://git@192.168.0.198:29418/test1" 可以将代码下载到本地

git push成功,但是这个是直接提交到git仓库了,没有经过gerrit

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

如果代码量很大会出现:

  1. git push
  2. Remote "origin" does not support the LFS locking API. Consider disabling it with:
  3. $ git config lfs.https://192.168.0.198/Mstar/MT9255/Domestic_3M_20200921/Domestic_3M_20200921.git/info/lfs.locksverify false
  4. batch request: fatal: Gerrit Code Review: git-lfs-authenticate: not found: exit status 1
  5. error: failed to push some refs to 'ssh://192.168.0.198:29418/Mstar/MT9255/Domestic_3M_20200921/Domestic_3M_20200921'

 

 

vi test2.c

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

这次不要直接提交,使用git push origin HEAD:refs/for/master测试

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

或者scp -p -P 29418 git@192.168.0.198: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了

  1. git log
  2. commit d21ab56c7eeffc42b9741528d792eb91c0a5cc01
  3. Author: xiangzi10 <xiangzi10@163.com>
  4. Date: Fri Dec 20 11:53:38 2019 +0800
  5. edit test1.c
  6. Change-Id: If00ec690d2a0566db14d1a8b37286a311a033e69
  7. commit 9addd694a33ceca1d50a9bb85e140c30444683d3
  8. Author: xiangzi10 <xiangzi10@163.com>
  9. Date: Fri Dec 20 09:24:23 2019 +0800
  10. modefy test2.c
  11. commit d6a30374a1175ea73a3c363c5f612885339fc13f
  12. Author: xiangzi10 <xiangzi10@163.com>
  13. Date: Thu Dec 19 16:54:13 2019 +0800
  14. add test2.c
  15. commit be31ebf1b464d95f079e2cfaed97f99509ff192b
  16. Author: xiangzi10 <xiangzi10@163.com>
  17. Date: Thu Dec 19 15:12:37 2019 +0800
  18. add test1.c
  19. commit 3123b4035d8cc48356f116173400552e9a82b109
  20. Author: git <git@192.168.0.198>
  21. Date: Thu Dec 19 13:41:40 2019 +0800
  22. Initial empty repository
  1. #git push origin HEAD:refs/for/master
  2. Counting objects: 5, done.
  3. Delta compression using up to 8 threads.
  4. Compressing objects: 100% (2/2), done.
  5. Writing objects: 100% (3/3), 324 bytes, done.
  6. Total 3 (delta 0), reused 0 (delta 0)
  7. remote: Processing changes: refs: 1, new: 1, done
  8. remote:
  9. remote: SUCCESS
  10. remote:
  11. remote: http://192.168.0.198:8081/c/test1/+/1 edit test1.c [NEW]
  12. remote:
  13. To ssh://git@192.168.0.198:29418/test1
  14. * [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://git@192.168.111.198: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://git@192.168.111.198: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://git@192.168.111.198: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://git@192.168.111.198:29418/MSD6A358/MSD6A358.git HEAD:refs/heads/master
To ssh://git@192.168.111.198:29418/MSD6A358/MSD6A358.git
 ! [rejected]        HEAD -> master (non-fast-forward)
error: failed to push some refs to 'ssh://git@192.168.111.198: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 git@192.168.111.198 gerrit create-project MSD6A358/MSD6A358.git

成功

#git push ssh://git@192.168.111.198: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://git@192.168.111.198:29418/MSD6A358/MSD6A358.git
 ! [remote rejected] HEAD -> master (n/a (unpacker error))
error: failed to push some refs to 'ssh://git@192.168.111.198:29418/MSD6A358/MSD6A358.git'

可能是commit 冲突

查看error_log

  1. [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'
  2. com.google.gerrit.sshd.BaseCommand$Failure: fatal: Unpack error, check server log
  3. at com.google.gerrit.sshd.commands.Receive.runImpl(Receive.java:129)
  4. at com.google.gerrit.sshd.AbstractGitCommand.service(AbstractGitCommand.java:107)
  5. at com.google.gerrit.sshd.AbstractGitCommand.access$000(AbstractGitCommand.java:32)
  6. at com.google.gerrit.sshd.AbstractGitCommand$1.run(AbstractGitCommand.java:72)
  7. at com.google.gerrit.sshd.BaseCommand$TaskThunk.run(BaseCommand.java:465)
  8. at com.google.gerrit.server.logging.LoggingContextAwareRunnable.run(LoggingContextAwareRunnable.java:110)
  9. at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
  10. at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  11. at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
  12. at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
  13. at com.google.gerrit.server.git.WorkQueue$Task.run(WorkQueue.java:610)
  14. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  15. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  16. at java.lang.Thread.run(Thread.java:748)
  17. Caused by: java.io.IOException: Unpack error on project "MSD6A358/MSD6A358_AN6.0_20190821":
  18. AdvertiseRefsHook: org.eclipse.jgit.transport.AdvertiseRefsHookChain@1bc2fb3dclass org.eclipse.jgit.transport.AdvertiseRefsHookChain
  19. at com.google.gerrit.sshd.commands.Receive.runImpl(Receive.java:128)
  20. ... 13 more
  21. Caused by: org.eclipse.jgit.errors.UnpackException: Exception while parsing pack stream
  22. at org.eclipse.jgit.transport.ReceivePack.service(ReceivePack.java:2233)
  23. at org.eclipse.jgit.transport.ReceivePack.receive(ReceivePack.java:2158)
  24. at com.google.gerrit.sshd.commands.Receive.runImpl(Receive.java:99)
  25. ... 13 more
  26. Caused by: java.lang.OutOfMemoryError: Java heap space
  27. at org.eclipse.jgit.internal.storage.pack.BinaryDelta.apply(BinaryDelta.java:163)
  28. at org.eclipse.jgit.internal.storage.pack.BinaryDelta.apply(BinaryDelta.java:118)
  29. at org.eclipse.jgit.transport.PackParser.resolveDeltas(PackParser.java:697)
  30. at org.eclipse.jgit.transport.PackParser.resolveDeltas(PackParser.java:673)
  31. at org.eclipse.jgit.transport.PackParser.resolveDeltas(PackParser.java:636)
  32. at org.eclipse.jgit.transport.PackParser.processDeltas(PackParser.java:613)
  33. at org.eclipse.jgit.transport.PackParser.parse(PackParser.java:584)
  34. at org.eclipse.jgit.internal.storage.file.ObjectDirectoryPackParser.parse(ObjectDirectoryPackParser.java:201)
  35. at org.eclipse.jgit.transport.ReceivePack.receivePack(ReceivePack.java:1502)
  36. at org.eclipse.jgit.transport.ReceivePack.receivePackAndCheckConnectivity(ReceivePack.java:1215)
  37. at org.eclipse.jgit.transport.ReceivePack.service(ReceivePack.java:2181)
  38. ... 15 more

原因是push的内容太大,超出jvm的空间。不太好解决,可以换个思路。

先将已有的项目scp到服务器gerrit仓库,然后建立连接即可:

#scp -r MSD6A358.git git@192.168.0.198:/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://git@192.168.0.198:29418/MSD6A358/MSD6A358      建立新连接

#git pull --rebase origin master

#scp -p -P 29418 git@192.168.0.198:hooks/commit-msg ".git/hooks/"

#git commit --amend

#git push origin HEAD:refs/for/master

成功

 

中间尝试:

#git push ssh://git@192.168.0.198: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://git@192.168.0.198:29418/MSD6A358/MSD6A358.git'

#git config remote.origin.url=git@192.168.0.198:/home/git/repositories/MSD6A358/MSD6A358_AN6.0_20190821.git

失败

#git push git@192.168.0.198: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.

失败

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/636827
推荐阅读
相关标签
  

闽ICP备14008679号