现在很多大型项目管理都是用git + gerrit的方式进行的,git-review作为一种比较方便的代码review工具,这里介绍基于Linux和windows的代码提交工具,当然不是直接提交到库上,这里是提交到Gerrit等大家review通过了,就可以让负责人merge到远程仓库上了。
1. Linux环境安装git-review
(1). 首先需要在Linux端安装python和pip,这里以uBuntu为例;
1204L:/mnt/e/firmware$ sudo apt-get install pip
[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'python3-pip' instead of 'pip'
The following additional packages will be installed:
......
1204L:/mnt/e/firmware$ sudo apt-get install python
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'python-is-python2' instead of 'python'
python-is-python2 is already the newest version (2.7.17-4).
0 upgraded, 0 newly installed, 0 to remove and 65 not upgraded.
(2) 然后安装 git-review 工具
1204L:/mnt/e/firmware$ pip install git-review
Collecting git-review
Downloading git_review-2.3.1-py3-none-any.whl (49 kB)
|████████████████████████████████| 49 kB 28 kB/s
Requirement already satisfied: requests>=1.1 in /usr/lib/python3/dist-packages (from git-review) (2.22.0)
Installing collected packages: git-review
WARNING: The script git-review is installed in '/home/user/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
(3)通过git-review提交代码到Gerrit
首先需要在Gerrit上添加本地生成的public key, 提交命令如下:
1204L:/mnt/e/firmware$ git-review project_fw_branch
2. Windows环境安装git-review
(1) 首先安装python和pip
windows下面的安装这两个工具,这里不啰嗦了。
(2) 使用pip安装git-review
这里通过命令窗口安装
C:\Users\user>pip install git-review
Collecting git-review
Downloading git_review-2.3.1-py3-none-any.whl (49 kB)
---------------------------------------- 49.4/49.4 KB 109.0 kB/s eta 0:00:00
Collecting requests>=1.1
Downloading requests-2.27.1-py2.py3-none-any.whl (63 kB)
---------------------------------------- 63.1/63.1 KB 70.5 kB/s eta 0:00:00
Collecting urllib3<1.27,>=1.21.1
Downloading urllib3-1.26.9-py2.py3-none-any.whl (138 kB)
---------------------------------------- 139.0/139.0 KB 24.4 kB/s eta 0:00:00
Collecting certifi>=2017.4.17
Downloading certifi-2022.5.18.1-py3-none-any.whl (155 kB)
---------------------------------------- 155.2/155.2 KB 15.8 kB/s eta 0:00:00
Collecting idna<4,>=2.5
Downloading idna-3.3-py3-none-any.whl (61 kB)
---------------------------------------- 61.2/61.2 KB 28.3 kB/s eta 0:00:00
Collecting charset-normalizer~=2.0.0
Downloading charset_normalizer-2.0.12-py3-none-any.whl (39 kB)
Installing collected packages: urllib3, idna, charset-normalizer, certifi, requests, git-review
Successfully installed certifi-2022.5.18.1 charset-normalizer-2.0.12 git-review-2.3.1 idna-3.3 requests-2.27.1 urllib3-1.26.9
WARNING: You are using pip version 22.0.4; however, version 22.1.1 is available.
You should consider upgrading via the 'd:\software\python3.7\python.exe -m pip install --upgrade pip' command.
(3) 通过TortoiseGit实现git-review提交
参考链接:https://loiy.net/post/524.html
在提交之前保证TortoiseGit的key和Gerrit添加的key匹配。
选择push选项之后,Local选择自己需要提交的分支;remote选项要输入refs/for/branch_name,否则提交不成功;
(4).通过git-bash实现git-review
软件环境搭建完成之后,通过git bash提交就比较简单了,跟linux下的命令一样,因为git bash就是在windows下面体验解析linux命令的。
1204L:/mnt/e/firmware$ git-review project_fw_branch