git and gerrit code review usage

作者: 30而立人 | 来源:发表于2016-05-16 17:30 被阅读846次

1,Environment preparation

  • Install git client on your PC
  • config the username and email
$ git config --global user.name "Firstname Lastname"
$ git config --global user.email "your_email@sap.com"```

* add the id_rsa.pub key to gerrit
  * copy the content from file 'C:\Users\iXXXXXX\\.ssh\id_rsa.pub' on your PC  ,if there is no this file,please generate one. You can go to https://git.wdf.sap.corp/#/settings/  and click 'SSH Public Keys' to add this key or find more details about how to add a public ssh key to gerrit.


### 2,SAP code review sites
* [SAP gerrit](https://git.wdf.sap.corp)-for the code review
* [SAP projectportal](https://projectportal.neo.ondemand.com)-for projects management

### 3,code review steps 
* step 1, get the project repository,where iXXXXXX is your ID number

$ git clone ssh://iXXXXXX@git.wdf.sap.corp:29418/master.git

* step 2, preparation

$ cd master ```
config the origin address

$ git config --local remote.origin.push HEAD:refs/for/master```
master branch setting

$ git config --local branch.master.remote origin
$ git config --local branch.master.rebase true

 set git auto generate commit id,where the 'iXXXXXX' is your ID number

$ scp -P 29418 iXXXXXX@git.wdf.sap.corp:hooks/commit-msg .git/hooks/```
show the current branch,usually, you will see 'master' branch only because there is only one branch on gerrit

$ git branch```
suppose there are two code reviews in progress,one local git branch only handle one review .the 'master' branch is default created after we get the git repository,so we need create another branch based on the remote branch to handle another review.

$ git branch develop remotes/origin/master
// create a develop branch
$ git config --local branch.develop.rebase true
$ git config --local branch.develop.remote origin
//develop branch setting```
usually, we should keep the local code up-to-date before we start to submit a review.

//$ git checkout master
//or
//$ git checkout develop
$ git pull
//or use 'git fetch' or ' git remote update'```
* step3, code changes and submit code reviews, suppose we have two code reviews. the one is on master branch,another one in on the develop branch. 

/**
* we start to use master branch to submit one code review
/
$ git checkout master
$ git pull
$ echo first review and first change >> readme.txt
$ git add readme.txt
$ git commit -m 'my first code review' //first commit should use this command and will generate a new code review
$ git push origin //push the last commit to gerrit review
$ echo first review and second change >>readme.txt //if review fail, we may need enhance our code
$ git add readme.txt
$ git commit --amend //use amend commit to put a review patch and will not generate a new review package
$ git push origin
$ echo first review and third change >> readme.txt
$ git add readme.txt
$ git commit --amend
/
*
* we start to use develop branch to submit another code review
*/
$ git checkout develop
$ git pull
$ echo second review and first change >> mmm.txt
$ git add mmm.txt
$ git commit -m 'my second code review'
$ echo second review and second change >> mmm.txt
$ git push origin```

  • step 4, your colleagues will help to finish this code review on gerrit

相关文章

网友评论

  • 轶匠:请问,就是我配置gerrit的时候可不可以直接指定我已经有了的git仓库?就是我之前代码都放在gogs上,gogs是一个类似gitlab和github的代码管理工具,我想代码还是在gogs上,通过gerrit code review之后可以同步到gogs上去
    30而立人:@一萝卜根儿 不好意思哦,这个我也没研究过,不过我觉得你可以新建一个git项目和你gogs上面一样的项目,在这个git项目上做一个钩子,正常的review都push到git项目上,然后钩子程序或者脚本自动同步到gogs上。

本文标题:git and gerrit code review usage

本文链接:https://www.haomeiwen.com/subject/lqrbrttx.html