1, what is Gerrit.
Gerrit is actually a git server that provides a series of permissions control for a git repository hosted on its server, and a web front page for code review. Of course, its main function is to do code Review. 2, Gerrit User Configuration Email activation Gerrit Account Settings interface, click "Contact Information" to enter the email register page, enter your own mailbox account ( This mailbox needs to be consistent with their own git configuration ). Multiple email accounts can be configured. Contact information SSH key configuration generates and reads the native SSH key via the following command:
ssh-keygen-t RSA
Cat ~/.ssh/id_rsa.pub
Copy Key content, in the Gerrit Account Settings page "SSH public Key" can be added.
Ssh-key
3, Gerrit daily use
3.1 Getting the code base
Log in Gerrit after the Projects-->list, select the appropriate project Your_project, enter the general interface of the project.
Select "Clone with Commit-msg Hook" and "SSH":
git clone ssh://your_account@review.xxxxx.com:29418/your_project && scp-p-P 29418 your_ Account@review.xxxxx.com:hooks/commit-msg cic-android/.git/hooks/
Copy the above command in your local git command-line window to pull the library code. 3.2 Gerrit Work flow 3.2.1 Upload a commit
Gerrit relative to Git provides a unique namespace "refs/for/" to define which branch our commits are uploaded to, and can be used to differentiate whether our commit is submitted to Gerrit for review or directly to the Git repository, in the following format:
Refs/for/<target-branch>
Push a commit to Gerrit:
$ git commit
$ git push origin Head:refs/for/master
Push a commit directly to the GIT repository: (we are not allowed to configure by default)
$ git commit
$ git push origin Head:master
When our commit push to Gerrit waits for review, Gerrit will save this commit in a staging branch called "Refs/changes/xx/yy/zz".
Where ZZ is the commit patch set number, YY is the change number, XX is the change number after two bits.
For example, the submission of this daming classmate in our project:
http://review.xxxxx.com:9090/#/c/545/
A total of 9 patches were submitted, and the 9th patch was saved in a branch named "REFS/CHANGES/45/545/9".
It can be verified by the download button in the upper right corner of the commit on the Gerrit page, for example, we select "Cherry Pick" and the command is as follows:
git fetch ssh://your_account@review.xxxxx.com:29418/your_project refs/changes/45/545/9 && git cherry-pick Fetch_head
Here, it is necessary to say a few concepts in order to understand:
Change
A change contains a change-id, which is automatically generated by the hooks (hooks/commit-msg) That is copied when we pull the replacement code library.
Contains one or more patch sets, as well as information such as Owner,project,target branch,comments.
Change-id
Change-id is a string of SHA-1 strings. There are hooks automatically generated under our commit message:
Feature:music play.
bugid:/
description:music play.
change-id:i3d087f04d9d94bfaa93b8609b988b300af537497
The change ID is unique in each branch of a project. Patch Set
A patch set is a commit,gerrit that generates a branch staging. A patch set for each commit in the change represents a new version of the change, automatically overwriting the previous patch set, and by default, only the last patch set is meaningful. When Code review is passed, it is only the last patch set that is merged into the specified branch.
Personal git work principle one
always be based on the latest remote library code work, try every step (especially Add/commit/push) through git pull--rebase to get the latest version of the current.
based on these principles, it is recommended that you reset the local commit to Gerrit immediately after you push it, or re-switch to a new branch job. 3.2.2 Upload a new patch set
When our commit is called back by reviewer, we may need to revise and resubmit it.
If our code is reset on the local branch, it can be obtained through the download method provided by the Gerrit page:
FETCH and checkout the change
//(Checkout command copied by change screen)
$ git fetch ssh://your_account@re View.xxxxx.com:29418/your_project REFS/CHANGES/45/545/9 && git checkout fetch_head
If you have previously worked by switching branches, you can re-switch back to the branch that contains this commit without executing the above command, and then you can modify it on this code to re-add,amend commit:
Rework the change
$ git add <path-of-reworked-file> ...
Amend commit
$ git commit--amend
//Push patch set
$ Git push origin Head:refs/for/master
3.2.3 Adding reviewers
Add related reviewers to the change interface. Consider using a plugin that automatically adds reviewers 3.2.4 Submit Change
The change is generally configured to submit only in the case of Code-review +2 and verified +1.
Submit when there may be a conflict, the interface will prompt "cannot Merge" words, you can first try to Gerrit page provides rebase function to do a rebase operation, if prompted conflict, you need to resolve the conflict locally after a patch Set to the change.
A process for local rebase:
Update the remote tracking branches
$ git fetch
/FETCH and checkout the change
//(Checkout command Copie D from change screen)
$ git fetch ssh://your_account@review.xxxxx.com:29418/your_project refs/changes/74/ 67374/2 && git checkout fetch_head
//Do the rebase
$ git rebase origin/master
//Resolve conflicts if Needed and stage the conflict resolution ...
$ git add <path-of-file-with-conflicts-resolved>
//Continue the rebase
$ git rebase--continue
// Push the commit with the conflict resolution as new patch set
$ Git push origin Head:refs/for/master
3.3 Multi-feature parallel development
Code review takes time for developers to develop other feature during this period, which results in a state of multi-feature parallel development.
To ensure that conflicts and dependencies are reduced, each feature should be developed in the feature own local branch, and this branch is based on the current head of the remote branch (target branch). That is, the latest code development based on remote libraries, rather than relying on some, some of the change in code review.
Of course, if necessary, you can also develop a new feature based on a change in code review, which will generate dependencies that can be seen in the Gerrit page of the change in "Related changes". This requires that reviewer also pay attention to this dependency and adjust the review timing.
Based on previous experience, it is strongly recommended that you do not generate this dependency and try to make every change submission non-dependent, avoiding the failure of the change to lead to various conflict-solving tasks.
Personal git working Principle II
as much as possible to ensure the integrity and independence of each change, and the smaller the better. 4, Advanced function 4.1 Web page code modification
Gerrit provides the ability to modify our patch code directly on a Web page, which is very handy for us to do minor problem changes (such as formatting problems, incorrect naming, extra spaces, etc.).
Edit
When you click Edit, the toolbar appears as follows:
Toolbar
Patch files can be modified, deleted, and so on.
If you want to edit somewhere in the file, click the review interface to enter the file:
Page_edit
Click the Edit button to enter edit mode and finish editing Save:
Save
Will be seen on the Change page, click Publish Edit button, Gerrit will automatically help you generate a patch containing just modified.
Publish
Patch 4.2 Drafts box features
Gerrit can be used as a copy of your own change box, we can upload a number of things that have not yet been completed, or do not want to submit review to this place. One can be used as a backup, in addition to multiple people to help each other to complete the same function, or on multiple computers (home, office) to deal with the unfinished work.
Unlike the "refs/for/" agreement, which submits a formal change, a change to the draft box is presented as "refs/drafts/", as follows:
$ git commit
$ git push origin Head:refs/drafts/luckyair
On the Gerrit page, in the Drafts column:
Draft
The change in the Drafts box can also be easily converted to a formal switch without having to re-use "refs/for/" to submit, click the Publish button to convert to a formal change, or delete this draft here.
Publish Draft
Author: Anly_jun
Links: Http://www.jianshu.com/p/b77fd16894b6
Source: Pinterest
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.