赞
踩
参考: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
- #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://git@192.168.0.198:29418/test1
- be31ebf..d6a3037 master -> master
如果代码量很大会出现:
- git push
- Remote "origin" does not support the LFS locking API. Consider disabling it with:
- $ git config lfs.https://192.168.0.198/Mstar/MT9255/Domestic_3M_20200921/Domestic_3M_20200921.git/info/lfs.locksverify false
- batch request: fatal: Gerrit Code Review: git-lfs-authenticate: not found: exit status 1
- 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测试
- #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 git@192.168.0.198: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://git@192.168.0.198:29418/test1
- ! [remote rejected] HEAD -> refs/for/master (commit 9addd69: missing Change-Id in message footer)
- 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了
- git log
- commit d21ab56c7eeffc42b9741528d792eb91c0a5cc01
- Author: xiangzi10 <xiangzi10@163.com>
- Date: Fri Dec 20 11:53:38 2019 +0800
-
- edit test1.c
-
- Change-Id: If00ec690d2a0566db14d1a8b37286a311a033e69
-
- commit 9addd694a33ceca1d50a9bb85e140c30444683d3
- Author: xiangzi10 <xiangzi10@163.com>
- Date: Fri Dec 20 09:24:23 2019 +0800
-
- modefy test2.c
-
- commit d6a30374a1175ea73a3c363c5f612885339fc13f
- Author: xiangzi10 <xiangzi10@163.com>
- Date: Thu Dec 19 16:54:13 2019 +0800
-
- add test2.c
-
- commit be31ebf1b464d95f079e2cfaed97f99509ff192b
- Author: xiangzi10 <xiangzi10@163.com>
- Date: Thu Dec 19 15:12:37 2019 +0800
-
- add test1.c
-
- commit 3123b4035d8cc48356f116173400552e9a82b109
- Author: git <git@192.168.0.198>
- 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://git@192.168.0.198: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://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
- [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 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.
失败
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。