我们以通过ssh上传我们的代码修改,Gerrit 支持两种形式的身份验证:用户的公钥或 kerberos。
如果要注册新的 SSH 密钥以与 Gerrit 一起使用, 要将id_rsa.pub 或 id_dsa.pub文件的内容粘贴到Settings的SSH Public Keys文本框中,然后单击“Add”按钮。如果文件内容不存在,可以创建一个新密钥。
- ssh-keygen -t rsa
- cat ~/.ssh/id_rsa.pub
【配置Kerberos】
Ubuntu在本地 SSH 配置中使用以下条目为 Gerrit 启用它:
- Host gerrit.mydomain.tld
- GSSAPIAuthentication yes
ssh -p 29418 username@gerritlocalhost
29418是Gerrit的运行端口。如果不清楚,可以访问获取
- curl http://gerritlocalhost/ssh_info
- gerritlocalhost 29418
经常需要上传的话,考虑添加 Gerrit 服务器到SSH Host添加到OpenSSH 客户端的配置文件(~/.ssh/config)中。如果需要开发一个自动化工具来执行向 Gerrit 的上传,推荐使用ssh来执行。
- cat ~/.ssh/config
- # ...
- # Host gerritlocalhost
- # Hostname gerritlocalhost
- # Port 29418
- # User yourname
由于 Gerrit 不提供交互式 shell,因此必须从 ssh 客户端触发命令,可协助自动化开发:link
- ssh -p 29418 username@gerritlocalhost gerrit –help
-
- gerrit [COMMAND] [ARG ...] [--] [--help (-h)]
- -- : end of options
- --help (-h) : display this help text
-
- Available commands of gerrit are:
- apropos Search in Gerrit documentation
- ban-commit Ban a commit from a project's repository
- close-connection Close the specified SSH connection
- create-account Create a new batch/role account
- create-branch Create a new branch
- create-group Create a new account group
- create-project Create a new project and associated Git repository
- flush-caches Flush some/all server caches from memory
- gc Run Git garbage collection
- gsql Administrative interface to active database
- index
- logging
- ls-groups List groups visible to the caller
- ls-members List the members of a given group
- ls-projects List projects visible to the caller
- ls-user-refs List refs visible to a specific user
- plugin
- query Query the change database
- receive-pack Standard Git server side command for client side git push
- rename-group Rename an account group
- review Apply reviews to one or more patch sets
- set-account Change an account's settings
- set-head Change HEAD reference for a project
- set-members Modify members of specific group or number of groups
- set-project Change a project's settings
- set-project-parent Change the project permissions are inherited from
- set-reviewers Add or remove reviewers on a change
- show-caches Display current cache statistics
- show-connections Display active client SSH connections
- show-queue Display the background work queues
- stream-events Monitor events occurring in real time
- test-submit
- version Display gerrit version
举例:
- # 查看某条提交的详细信息
- ssh -p 29418 username@gerritlocalhost gerrit query change:<GerritID>
-
- # 查看GerritID change提交到的project&&branch信息::
- ssh -p 29418 username@gerritlocalhost gerrit query change:<GerritID> | grep "project" | awk -F ": " '{print$2}'
- ssh -p 29418 username@gerritlocalhost gerrit query change:<GerritID> | grep "branch" | awk -F ": " '{print$2}'
-
- # 针对Iac6b2ac2 change 添加reviewer alice和bob 并删除reviewer eve
- ssh -p 29418 review.example.com gerrit set-reviewers \
- -a alice@example.com -a bob@example.com -r eve@example.com Iac6b2ac2
- # 针对Iac6b2ac2 change 添加所有的project owners为reviewer
- ssh -p 29418 review.example.com gerrit set-reviewers -a "'Project Owners'" Iac6b2ac2
- # 再myproject 的特定的1935 change 添加eve作为reviewer????
- ssh -p 29418 review.example.com gerrit set-reviewers --project myproject -a eve@example.com 1935
-
- # verity +1命令:
- ssh -p 29418 username@gerritlocalhost gerrit review --verified +1 -m "......" <GerritID>,<PATCHSET_NUM>
- # SLTApproved: --sltapproved +1
- # SME granted: --sme-granted +1
- # Submit approved: --sumbit-approved +1
- # code review:--code-review +2
- # abandon change:--abandon
- # delete:--delete
-
- #添加comment信息:
- ssh -p 29418 username@gerritlocalhost gerrit review -m '"......"' <GerritID>,<PATCHSET_NUM>
- # 添加tag: --tag or -t
-
- # 将分支“master”上“MyProject”中的更改“I6686e64a788365bd252df69ae5b3ec9d65aaf068”的主题设置为“MyTopic”。
- ssh -p 29418 username@gerritlocalhost gerrit set-topic MyProject~master~I6686e64a788365bd252df69ae5b3ec9d65aaf068 --topic MyTopic
-
- # 查看所有匹配 tools的项目名:
- ssh -p 29418 gerritlocalhost gerrit ls-projects --match "tools"
- # ssh -p 29418 username@gerritlocalhost gerrit ls-projects
- # 等效于:curl http://gerritlocalhost/projects/
- # 添加forest:curl http://gerritlocalhost/projects/tools
-
- # 跳过2条,查询tools/gerrit库的待合入2条changes:
- ssh -p 29418 username@gerritlocalhost gerrit query --format=JSON status:open project:tools/gerrit limit:2 --start 2
-
- # 从项目“myproject”的“master”分支或者f06124a这个revision切出,创建一个名为“newbranch”的新分支。
- ssh -p 29418 gerritlocalhost gerrit create-branch myproject newbranch master
- ssh -p 29418 gerritlocalhost gerrit create-branch myproject newbranch f06124a
-
- # 查看ssh连接数(可用于查看有多少人在做代码拉取或推送操作,有利于判断服务器的压力):
- ssh -p 29418 username@gerritlocalhost gerrit show-queue -w
-
- # 查看所有缓存(分析服务器缓存情况):
- ssh -p 29418 username@gerritlocalhost gerrit show-caches
-
- # 查看可刷新缓存(更新数据):
- ssh -p 29418 username@gerritlocalhost gerrit flush-caches --list
-
- # 刷新指定缓存——项目列表:
- ssh -p 29418 username@gerritlocalhost gerrit flush-caches --cache projects
-
- # 设置项目合并commit方式(merge->rebase)
- ssh -p 29418 username@gerritlocalhost gerrit set-project example --submit-type REBASE_IF_NECESSARY
-
- # 针对myproject代码库需要更改ID时候,选择rebase方式合并
- ssh -p 29418 gerritlocalhost gerrit set-project myproject --submit-type MERGE_IF_NECESSARY --change-id true --content-merge false --project-state HIDDEN
参考链接:
https://gerrit-review.googlesource.com/Documentation/cmd-index.html