1. 先設置本地git的用戶信息
1 2 |
$ git config --global user.name "John Doe" $ git config --global user.email [email protected] |
2. Who is Admin
The first user to login automatically gets the administrator status.
Create a the new Git repository in Gerrit via the following command.
1 2 3 4 |
# assumes that Gerrit runs on port 29418 # on localhost ssh -p 29418 <userid>@localhost gerrit create-project demo/gerrittest |
3. For Developer
You can also do this setup directly via the Git command line.
1 |
git config remote.origin.push refs/heads/*:refs/for/* |
3.1. 設置full-name、郵箱
進入帳號設置,驗證郵箱並設置Full-Name。
郵箱驗證會發驗證郵件到郵箱。
3.2. 添加公匙
在~/.ssh下執行 ssh-keygen 來生成密鑰對(公鑰/私鑰)。
1 |
ssh-keygen -C "test gerrit for developerA" -f id_developera |
執行後,會在目錄下面生成文件:id_developera(私鑰),id_developera.pub(公鑰)。
將公鑰的內容拷貝到gerrit網站上帳號設置》”SSH Public Keys“。
3.3. Cygwin多個SSH帳號設置
同樣,在~/.ssh 下生成密鑰對,在gerrit網站上設置帳號的公鑰。
1 |
ssh-keygen -C "test gerrit for developerB" -f id_developerb |
在Cygwin中設置新的SSH 連接。在 ~/.ssh/config 中設置:
1 2 3 4 5 6 7 8 9 10 11 |
Host gerrit-developerA Hostname localhost Port 29418 User developerA IdentityFile /home/ethan/.ssh/id_developera Host gerrit-developerB Hostname localhost Port 29418 User developerB IdentityFile /home/ethan/.ssh/id_developerb |
在ssh-agent中註冊:
1 2 3 |
eval `ssh-agent -s` ssh-add /home/ethan/.ssh/id_developerb ssh-add -l # 列出添加的內容 |
3.4. 安裝change-id hook
下載gerrit-site上的committ-msg hook,例如: http://localhost:7666/gerrit/tools/hooks/commit-msg
拷貝到項目的.git/hooks 目錄下。
有了這個hook,每次commit都會生成一個Change ID到comment裏邊。
例如:
1 2 3 4 5 6 7 |
commit bfd38249b52bad688e7f71dd4b26ee189e02ef10 Author: developerA <[email protected]> Date: Sun Feb 9 15:24:49 2014 +0800 add second file Change-Id: I7bdc292c32696a733e445a2afa4cb03ed2d07acc |
3.5. 修改並提交Commit(to review)
例子:
git push origin master:refs/for/master
將會生成一個 review在gerrit網站上。
3.6. 處理衝突
提交review的commit已經落後於gerrit上目標分支,不是fast-forward提交:
可能會產生自動merge;
也可能會產生conflict;
所以如果長時間沒有push,那麼先下載目標分支rebase一下:
git pull –rebase # 此處命令省略 remote分支參數,讀者根據需要自己添加。
如果產生Conflict,那就需要pull –rebase一下,然後手動修改解決conflict,git add修改的文件。
重新提交commit去review。如果想修改下commit message,說明下新的修改,可以使用 git commit –amend,但是不要修改message中自動生成的change-id。
4. For Reviewer
4.1. Reviewing a change request
導航菜單 All > Open 列出所有待reviewer的CR
CR詳情:
點擊Side-by-Side,查看修改。Commit Message也能進行review。
點擊右側行號,可以添加comment。
4.2. Publishing your review result
點Review就可以將評審結果發佈出來。可以打分 +2 到 -2。
點擊 Publish and Submit,發佈評審結果的同時,將Change提交到目標branch上。
5. For All Users
下載CR的commit
gerrit網站CR詳情頁面提供下載各種命令:
6. Gerrit網站按“?”顯示快捷鍵提醒
7. 參考
- http://www.vogella.com/tutorials/Gerrit/article.html
- http://blog.csdn.net/yz2574648679/article/details/10362747
7.1. 更多資料
- Gerrit Code Review - A Quick Introduction
- Gerrit at Eclipse