参考资料


Gerrit工作流程及使用手册

环境配置


生成ssh key

ssh-keygen -t rsa -C "[email protected]"

//默认路径
/Users/zhouqirui/.ssh/id_rsa

在 *.pub文件内复制,全部内容复制到gerrit的SSH配置目录

** 注意:密码,留空全部默认,否则push验证会出错误

对git使用端口和ip指定使用加密协议

由于OpenSSH从8.8版本由于安全原因开始弃用了rsa加密的密钥,因为OpenSSH认为rsa破解成本已经低于5万美元,所以觉得成本太小了,有风险就给禁用了,所以最小版本须要制定升级使用协议类型,

//1 指定路径生成文件
touch /Users/zhouqirui/.ssh/config

//2 并在上述文件指定使用协议 外网ip(172.18.200.198),使用前需要挂vpn
Host 192.168.31.65
HostName 192.168.31.65
User zhouqirui
PubkeyAcceptedKeyTypes +ssh-rsa
IdentityFile ~/.ssh/id_rsa
Port 29418

更改系统SSH配置

//路径 
sudo nano /etc/ssh/ssh_config

//macos 10.13.4 以上 增加如下内容
HostkeyAlgorithms ssh-dss,ssh-rsa
KexAlgorithms +diffie-hellman-group1-sha1

//macos 其它版本 增加如下内容
MACs hmac-md5,hmac-sha1,[email protected],hmac-ripemd160
HostkeyAlgorithms ssh-dss,ssh-rsa
KexAlgorithms +diffie-hellman-group1-sha1

配置 Gerrit Web SSH

image

git clone 路径 (建议用终端clone 用sourcetree 还要手动配置 hooks)

image

git配置

//项目根目录下配置GIT
git config remote.origin.push refs/heads/*:refs/for/*

自定义Push (sourcetree 自带PUSH不能使用,暂时没解决办法)

v1 使用脚本自定上传指定分支(推荐)

image

//1.路径
/Users/zhouqirui/Desktop/shell/push2gerrit.sh

//2.内容
#!/bin/sh
 
#  push.sh
#  KeepRunning
 
# 获取当前分支名
branch=$(git symbolic-ref --short -q HEAD)
# push review
git push origin HEAD:refs/for/${branch}

v2 单独指定目录路径

image

/usr/bin/git

push ssh://[email protected]:29418/Ios develop:refs/for/develop

使用(以下内容,没有管理权限的可以不看了)


Gerrit 审核参考 (需要有权限)

image

审核不过(处理)

image

'更正上一次提交' 选项 

该用法确保使用上一次记录重新提交,使用上次生成唯一 commit ID

合并commit

//1.最近2条记录
git rebase -i HEAD~2

//2.合并改写 (退出命令 esc :wq)
pick b0f97ef7d c1
squash a61e4a8fb c2

# Rebase 8df25e817..a61e4a8fb onto 8df25e817 (2 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

//3. 查看记录
git log

//4.正常提交