接入Gerrit手册
<p>[toc]</p>
<table>
<thead>
<tr>
<th>最后修订日期</th>
<th>2023年10月30日</th>
</tr>
</thead>
<tbody>
<tr>
<td>作者</td>
<td>林七佛</td>
</tr>
<tr>
<td>V1.0.0</td>
<td>创建文档</td>
</tr>
</tbody>
</table>
<p>> 虚拟实验室-生产效能小组成员已验证此文档有效性,作为后续组件化-3D领域-规范使用
故编写此文档。</p>
<h3>修改git用户名和邮箱</h3>
<p>在git bash上执行命令修改用户名和邮箱(用户名必须是你的姓名,邮箱必须是你的工号@nd.com):</p>
<p>1) 修改全局用户名的命令:<code>git config --global user.name</code> 你的姓名;
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=af6a101fd1b381824d5d5a23d3225dee&amp;file=file.png" alt="" />
2) 修改当前全局提交邮箱的命令:<code>git config --global user.email</code> 你的工号@nd.com;
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=497ddbef2514a27186eb4a2edc547846&amp;file=file.png" alt="" />
配置完后,使用命令 <code>git config --global -l</code>查看一下是否配置成功
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=1b187d8156c15dbb79fa27df46c9364f&amp;file=file.png" alt="" /></p>
<h3>设置SSH Key</h3>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=7f4b2e10afa32de1a40ba68af894d974&amp;file=file.png" alt="" /></p>
<pre><code>打开目录C:\Users\Administrator\.ssh,查看是否有id_rsa.pub文件。
如没有,运行GitBash(安装Git客户端后,右键菜单中会有),执行ssh-keygen,一路回车生成一对密钥。
登录登录Gerrit门户:http://gerrit.sdp.nd/ 贴到下面页面中</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=4aa3d483bf23ac207cf3d9ed37214426&amp;file=file.png" alt="" /></p>
<h3>gerrit拉取代码</h3>
<h4>1.在gerrit.sdp.nd上选择项目列表中的相关项目,复制命令</h4>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=68cc60238f82353dbef4d4c9106b151e&amp;file=file.png" alt="" /></p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=abc444be65f0b8b391a4c75bd357581c&amp;file=file.png" alt="" /></p>
<h4>2.复制clone命令,在Git Bash里面执行。必须重新clone项目,注意一定要在Git Bash中执行</h4>
<p>如果拉取中出现下面提示
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=69f78003302b37031e800ef68ca3fd2e&amp;file=file.png" alt="" /></p>
<pre><code>把&amp;&amp; scp -p -P 修改为&amp;&amp; scp -O -P再次拉取,确保能看到commit-msg,否则提交到gerrit的时候回报&quot;Missing Change Id&quot;错误</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=620bdec2dc1cb256a403f5c4541f99d3&amp;file=file.png" alt="" /></p>
<p>如果拉取出现Unable to negotiate with *<strong>** port </strong>:no matching host key type found的问题
可以参考下面的解决方法
<a href="https://blog.csdn.net/m0_47147246/article/details/129670943">https://blog.csdn.net/m0_47147246/article/details/129670943</a></p>
<h3>提交代码到评审分支</h3>
<pre><code>提交到要求评审的分支,如测试分支和主干分支,在push的时候需要改一下remote branch,如下图所示,需要在分支名称前添加“refs/for/”</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=b9e71433a65a7aa79f26515610f2402a&amp;file=file.png" alt="" /></p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=ffdfdfe7afcdf2efce4c1405b1f3a098&amp;file=file.png" alt="" /></p>
<h3>代码评审</h3>
<p>TBD</p>
<h3>如何关闭git push权限</h3>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=74193d2b4f57731b490e753f53feee25&amp;file=file.png" alt="" /></p>
<h3>如何设置gerrit直接提交,不需评审</h3>
<p>1、增加这个Reference
<img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=03d982a9ac69ff53debae38cfde5c996&amp;file=file.png" alt="" />
2、push时使用命令,增加后缀%submit,如
git push origin master:refs/for/master%submit</p>
<h3>参考链接</h3>
<p>[工程院编码流程规范](<a href="https://docs.qq.com/doc/DQlN4V29xVnN3eWdV">https://docs.qq.com/doc/DQlN4V29xVnN3eWdV</a> "工程院编码流程规范")
[Gerrit FAQ](<a href="https://wiki.doc.101.com/index.php?title=Gerrit_FAQ">https://wiki.doc.101.com/index.php?title=Gerrit_FAQ</a> "Gerrit FAQ")</p>