blob: b9bdad099926e393de08be53faaa7d929ab0fce9 [file] [log] [blame]
Edwin Kempin1f556222015-04-22 13:24:39 +02001= User Guide
2
3This is a Gerrit guide that is dedicated to Gerrit end-users. It
4explains the standard Gerrit workflows and how a user can adapt Gerrit
5to personal preferences.
6
7It is expected that readers know about link:http://git-scm.com/[Git]
8and that they are familiar with basic git commands and workflows.
9
10[[gerrit]]
11== What is Gerrit?
12
13Gerrit is a Git server that provides link:access-control.html[access
14control] for the hosted Git repositories and a web front-end for doing
15link:#code-review[code review]. Code review is a core functionality of
16Gerrit, but still it is optional and teams can decide to
17link:#no-code-review[work without code review].
18
19[[tools]]
20== Tools
21
22Gerrit speaks the git protocol. This means in order to work with Gerrit
23you do *not* need to install any Gerrit client, but having a regular
24git client, such as the link:http://git-scm.com/[git command line] or
25link:http://eclipse.org/egit/[EGit] in Eclipse, is sufficient.
26
27Still there are some client-side tools for Gerrit, which can be used
28optionally:
29
30* link:http://eclipse.org/mylyn/[Mylyn Gerrit Connector]: Gerrit
31 integration with Mylyn
Edwin Kempin4cb451e2015-05-08 09:07:51 +020032* link:https://github.com/uwolfer/gerrit-intellij-plugin[Gerrit
33 IntelliJ Plugin]: Gerrit integration with the
34 link:http://www.jetbrains.com/idea/[IntelliJ Platform]
Edwin Kempin1f556222015-04-22 13:24:39 +020035* link:https://play.google.com/store/apps/details?id=com.jbirdvegas.mgerrit[
36 mGerrit]: Android client for Gerrit
37* link:https://github.com/stackforge/gertty[Gertty]: Console-based
38 interface for Gerrit
39
40[[clone]]
41== Clone Gerrit Project
42
43Cloning a Gerrit project is done the same way as cloning any other git
44repository by using the `git clone` command.
45
46.Clone Gerrit Project
47----
48 $ git clone ssh://gerrithost:29418/RecipeBook.git RecipeBook
49 Cloning into RecipeBook...
50----
51
52The URL for cloning the project can be found in the Gerrit web UI
53under `Projects` > `List` > <project-name> > `General`.
54
55For git operations Gerrit supports the link:user-upload.html#ssh[SSH]
56and the link:user-upload.html#http[HTTP/HTTPS] protocols.
57
58[NOTE]
59To use SSH you must link:user-upload.html#configure_ssh[generate an SSH
60key pair and upload the public SSH key to Gerrit].
61
62[[code-review]]
63== Code Review Workflow
64
65With Gerrit _Code Review_ means to link:#review-change[review] every
66commit *before* it is accepted into the code base. The author of a code
67modification link:user-upload.html#push_create[uploads a commit] as a
68change to Gerrit. In Gerrit each change is stored in a
69link:#change-ref[staging area] where it can be checked and reviewed.
70Only when it is approved and submitted it gets applied to the code
71base. If there is feedback on a change, the author can improve the code
72modification by link:#upload-patch-set[amending the commit and
73uploading the new commit as a new patch set]. This way a change is
74improved iteratively and it is applied to the code base only when is
75ready.
76
77[[upload-change]]
78== Upload a Change
79
80Uploading a change to Gerrit is done by pushing a commit to Gerrit. The
81commit must be pushed to a ref in the `refs/for/` namespace which
82defines the target branch: `refs/for/<target-branch>`.
83The magic `refs/for/` prefix allows Gerrit to differentiate commits
84that are pushed for review from commits that are pushed directly into
85the repository, bypassing code review. For the target branch it is
86sufficient to specify the short name, e.g. `master`, but you can also
87specify the fully qualified branch name, e.g. `refs/heads/master`.
88
89.Push for Code Review
90----
91 $ git commit
92 $ git push origin HEAD:refs/for/master
93
94 // this is the same as:
95 $ git commit
96 $ git push origin HEAD:refs/for/refs/heads/master
97----
98
99.Push with bypassing Code Review
100----
101 $ git commit
102 $ git push origin HEAD:master
103
104 // this is the same as:
105 $ git commit
106 $ git push origin HEAD:refs/heads/master
107----
108
109[[push-fails]]
110[NOTE]
111If pushing to Gerrit fails consult the Gerrit documentation that
112explains the link:error-messages.html[error messages].
113
114[[change-ref]]
115When a commit is pushed for review, Gerrit stores it in a staging area
116which is a branch in the special `refs/changes/` namespace. A change
117ref has the format `refs/changes/XX/YYYY/ZZ` where `YYYY` is the
118numeric change number, `ZZ` is the patch set number and `XX` is the
119last two digits of the numeric change number, e.g.
120`refs/changes/20/884120/1`. Understanding the format of this ref is not
121required for working with Gerrit.
122
123[[fetch-change]]
124Using the change ref git clients can fetch the corresponding commit,
125e.g. for local verification.
126
127.Fetch Change
128----
129 $ git fetch https://gerrithost/myProject refs/changes/74/67374/2 && git checkout FETCH_HEAD
130----
131
132[NOTE]
133The fetch command can be copied from the
134link:user-review-ui.html#download[download commands] in the change
135screen.
136
137The `refs/for/` prefix is used to map the Gerrit concept of
138"Pushing for Review" to the git protocol. For the git client it looks
139like every push goes to the same branch, e.g. `refs/for/master` but in
140fact for each commit that is pushed to this ref Gerrit creates a new
141branch under the `refs/changes/` namespace. In addition Gerrit creates
142an open change.
143
144[[change]]
145A change consists of a link:user-changeid.html[Change-Id], meta data
146(owner, project, target branch etc.), one or more patch sets, comments
147and votes. A patch set is a git commit. Each patch set in a change
148represents a new version of the change and replaces the previous patch
149set. Only the latest patch set is relevant. This means all failed
150iterations of a change will never be applied to the target branch, but
151only the last patch set that is approved is integrated.
152
153[[change-id]]
154The Change-Id is important for Gerrit to know whether a commit that is
155pushed for code review should create a new change or whether it should
156create a new patch set for an existing change.
157
158The Change-Id is a SHA-1 that is prefixed with an uppercase `I`. It is
159specified as footer in the commit message (last paragraph):
160
161----
162 Improve foo widget by attaching a bar.
163
164 We want a bar, because it improves the foo by providing more
165 wizbangery to the dowhatimeanery.
166
167 Bug: #42
168 Change-Id: Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b
169 Signed-off-by: A. U. Thor <author@example.com>
170----
171
172If a commit that has a Change-Id in its commit message is pushed for
173review, Gerrit checks if a change with this Change-Id already exists
174for this project and target branch, and if yes, Gerrit creates a new
175patch set for this change. If not, a new change with the given
176Change-Id is created.
177
178If a commit without Change-Id is pushed for review, Gerrit creates a
179new change and generates a Change-Id for it. Since in this case the
180Change-Id is not included in the commit message, it must be manually
181inserted when a new patch set should be uploaded. Most projects already
182link:project-configuration.html#require-change-id[require a Change-Id]
183when pushing the very first patch set. This reduces the risk of
184accidentally creating a new change instead of uploading a new patch
185set. Any push without Change-Id then fails with
186link:error-missing-changeid.html[missing Change-Id in commit message
187footer]. New patch sets can always be uploaded to a specific change
188(even without any Change-Id) by pushing to the change ref, e.g.
189`refs/changes/74/67374`.
190
191Amending and rebasing a commit preserves the Change-Id so that the new
192commit automatically becomes a new patch set of the existing change,
193when it is pushed for review.
194
195.Push new Patch Set
196----
197 $ git commit --amend
198 $ git push origin HEAD:refs/for/master
199----
200
201Change-Ids are unique for a branch of a project. E.g. commits that fix
202the same issue in different branches should have the same Change-Id,
203which happens automatically if a commit is cherry-picked to another
204branch. This way you can link:user-search.html[search] by the Change-Id
205in the Gerrit web UI to find a fix in all branches.
206
207Change-Ids can be created automatically by installing the `commit-msg`
208hook as described in the link:user-changeid.html#creation[Change-Id
209documentation].
210
211Instead of manually installing the `commit-msg` hook for each git
212repository, you can copy it into the
213link:http://git-scm.com/docs/git-init#_template_directory[git template
214directory]. Then it is automatically copied to every newly cloned
215repository.
216
217[[review-change]]
218== Review Change
219
220After link:#upload-change[uploading a change for review] reviewers can
221inspect it via the Gerrit web UI. Reviewers can see the code delta and
222link:user-review-ui.html#inline-comments[comment directly in the code]
223on code blocks or lines. They can also link:user-review-ui.html#reply[
224post summary comments and vote on review labels]. The
225link:user-review-ui.html[documentation of the review UI] explains the
226screens and controls for doing code reviews.
227
228There are several options to control how patch diffs should be
229rendered. Users can configure their preferences in the
230link:user-review-ui.html#diff-preferences[diff preferences].
231
232[[upload-patch-set]]
233== Upload a new Patch Set
234
235If there is feedback from code review and a change should be improved a
236new patch set with the reworked code should be uploaded.
237
238This is done by amending the commit of the last patch set. If needed
239this commit can be fetched from Gerrit by using the fetch command from
240the link:user-review-ui.html#download[download commands] in the change
241screen.
242
243It is important that the commit message contains the
244link:user-changeid.html[Change-Id] of the change that should be updated
245as a footer (last paragraph). Normally the commit message already
246contains the correct Change-Id and the Change-Id is preserved when the
247commit is amended.
248
249.Push Patch Set
250----
251 // fetch and checkout the change
252 // (checkout command copied from change screen)
253 $ git fetch https://gerrithost/myProject refs/changes/74/67374/2 && git checkout FETCH_HEAD
254
255 // rework the change
256 $ git add <path-of-reworked-file>
257 ...
258
259 // amend commit
260 $ git commit --amend
261
262 // push patch set
263 $ git push origin HEAD:refs/for/master
264----
265
266[NOTE]
267Never amend a commit that is already part of a central branch.
268
269Pushing a new patch set triggers email notification to the reviewers.
270
271[[multiple-features]]
272== Developing multiple Features in parallel
273
274Code review takes time, which can be used by the change author to
275implement other features. Each feature should be implemented in its own
276local feature branch that is based on the current HEAD of the target
277branch. This way there is no dependency to open changes and new
278features can be reviewed and applied independently. If wanted, it is
279also possible to base a new feature on an open change. This will create
280a dependency between the changes in Gerrit and each change can only be
281applied if all its predecessor are applied as well. Dependencies
282between changes can be seen from the
283link:user-review-ui.html#related-changes-tab[Related Changes] tab on
284the change screen.
285
286[[watch]]
287== Watching Projects
288
289To get to know about new changes you can link:user-notify.html#user[
290watch the projects] that you are interested in. For watched projects
291Gerrit sends you email notifications when a change is uploaded or
292modified. You can decide on which events you want to be notified and
293you can filter the notifications by using link:user-search.html[change
294search expressions]. For example '+branch:master file:^.*\.txt$+' would
295send you email notifications only for changes in the master branch that
296touch a 'txt' file.
297
298It is common that the members of a project team watch their own
299projects and then pick the changes that are interesting to them for
300review.
301
302Project owners may also configure
303link:intro-project-owner.html#notifications[notifications on
304project-level].
305
306[[adding-reviewers]]
307== Adding Reviewers
308
309In the link:user-review-ui.html#reviewers[change screen] reviewers can
310be added explicitly to a change. The added reviewer will then be
311notified by email about the review request.
312
313Mainly this functionality is used to request the review of specific
314person who is known to be an expert in the modified code or who is a
315stakeholder of the implemented feature. Normally it is not needed to
316explicitly add reviewers on every change, but you rather rely on the
317project team to watch their project and to process the incoming changes
318by importance, interest, time etc.
319
320There are also link:intro-project-owner.html#reviewers[plugins which
321can add reviewers automatically] (e.g. by configuration or based on git
322blame annotations). If this functionality is required it should be
323discussed with the project owners and the Gerrit administrators.
324
325[[dashboards]]
326== Dashboards
327
328Gerrit supports a wide range of link:user-search.html#search-operators[
329query operators] to search for changes by different criteria, e.g. by
330status, change owner, votes etc.
331
332The page that shows the results of a change query has the change query
333contained in its URL. This means you can bookmark this URL in your
334browser to save the change query. This way it can be easily re-executed
335later.
336
337Several change queries can be also combined into a dashboard. A
338dashboard is a screen in Gerrit that presents the results of several
339change queries in different sections, each section having a descriptive
340title.
341
342A default dashboard is available under `My` > `Changes`. It has
343sections to list outgoing reviews, incoming reviews and recently closed
344changes.
345
346Users can also define link:user-dashboards.html#custom-dashboards[
347custom dashboards]. Dashboards can be bookmarked in a browser so that
348they can be re-executed later.
349
350It is also possible to link:#my-menu[customize the My menu] and add
351menu entries for custom queries or dashboards to it.
352
353Dashboards are very useful to define own views on changes, e.g. you can
354have different dashboards for own contributions, for doing reviews or
355for different sets of projects.
356
357[NOTE]
358You can use the link:user-search.html#limit[limit] and
359link:user-search.html#age[age] query operators to limit the result set
360in a dashboard section. Clicking on the section title executes the
361change query without the `limit` and `age` operator so that you can
362inspect the full result set.
363
364Project owners can also define shared
365link:user-dashboards.html#project-dashboards[dashboards on
366project-level]. The project dashboards can be seen in the web UI under
367`Projects` > `List` > <project-name> > `Dashboards`.
368
369[[submit]]
370== Submit a Change
371
372Submitting a change means that the code modifications of the current
373patch set are applied to the target branch. Submit requires the
374link:access-control.html#category_submit[Submit] access right and is
375done on the change screen by clicking on the
376link:user-review-ui.html#submit[Submit] button.
377
378In order to be submittable changes must first be approved by
379link:user-review-ui.html#vote[voting on the review labels]. By default
380a change can only be submitted if it has a vote with the highest value
381on each review label and no vote with the lowest value (veto vote).
382Projects can configure link:intro-project-owner.html#labels[custom
383labels] and link:intro-project-owner.html#submit-rules[custom submit
384rules] to control when a change becomes submittable.
385
386How the code modification is applied to the target branch when a change
387is submitted is controlled by the
388link:project-configuration.html#submit_type[submit type] which can be
389link:intro-project-owner.html#submit-type[configured on project-level].
390
391Submitting a change may fail with conflicts. In this case you need to
392link:#rebase[rebase] the change locally, resolve the conflicts and
393upload the commit with the conflict resolution as new patch set.
394
395If a change cannot be merged due to path conflicts this is highlighted
396on the change screen by a bold red `Cannot Merge` label.
397
398[[rebase]]
399== Rebase a Change
400
401While a change is in review the HEAD of the target branch can evolve.
402In this case the change can be rebased onto the new HEAD of the target
403branch. When there are no conflicts the rebase can be done directly
404from the link:user-review-ui.html#rebase[change screen], otherwise it
405must be done locally.
406
407.Rebase a Change locally
408----
409 // update the remote tracking branches
410 $ git fetch
411
412 // fetch and checkout the change
413 // (checkout command copied from change screen)
414 $ git fetch https://gerrithost/myProject refs/changes/74/67374/2 && git checkout FETCH_HEAD
415
416 // do the rebase
417 $ git rebase origin/master
418
419 // resolve conflicts if needed and stage the conflict resolution
420 ...
421 $ git add <path-of-file-with-conflicts-resolved>
422
423 // continue the rebase
424 $ git rebase --continue
425
426 // push the commit with the conflict resolution as new patch set
427 $ git push origin HEAD:refs/for/master
428----
429
430Doing a manual rebase is only necessary when there are conflicts that
431cannot be resolved by Gerrit. If manual conflict resolution is needed
432also depends on the link:intro-project-owner.html#submit-type[submit
433type] that is configured for the project.
434
435Generally changes shouldn't be rebased without reason as it
436increases the number of patch sets and creates noise with
437notifications. However if a change is in review for a long time it may
438make sense to rebase it from time to time, so that reviewers can see
439the delta against the current HEAD of the target branch. It also shows
440that there is still an interest in this change.
441
442[NOTE]
443Never rebase commits that are already part of a central branch.
444
445[[abandon]]
446[[restore]]
447== Abandon/Restore a Change
448
449Sometimes during code review a change is found to be bad and it should
450be given up. In this case the change can be
451link:user-review-ui.html#abandon[abandoned] so that it doesn't appear
452in list of open changes anymore.
453
454Abandoned changes can be link:user-review-ui.html#restore[restored] if
455later they are needed again.
456
457[[topics]]
458== Using Topics
459
460Changes can be grouped by topics. This is useful because it allows you
461to easily find related changes by using the
462link:user-search.html#topic[topic search operator]. Also on the change
463screen link:user-review-ui.html#same-topic[changes with the same topic]
464are displayed so that you can easily navigate between them.
465
466Often changes that together implement a feature or a user story are
467group by a topic.
468
469Assigning a topic to a change can be done in the
470link:user-review-ui.html#project-branch-topic[change screen].
471
472It is also possible to link:user-upload.html#topic[set a topic on
473push].
474
475.Set Topic on Push
476----
477 $ git push origin HEAD:refs/for/master%topic=multi-master
478----
479
480[[drafts]]
481== Working with Drafts
482
483Changes can be uploaded as drafts. By default draft changes are only
484visible to the change owner. This gives you the possibility to have
485some staging before making your changes visible to the reviewers. Draft
486changes can also be used to backup unfinished changes.
487
488A draft change is created by pushing to the magic
489`refs/drafts/<target-branch>` ref.
490
491.Push a Draft Change
492----
493 $ git commit
494 $ git push origin HEAD:refs/drafts/master
495----
496
497Draft changes have the state link:user-review-ui.html#draft[Draft] and
498can be link:user-review-ui.html#publish[published] or
499link:user-review-ui.html#delete[deleted] from the change screen.
500
501By link:user-review-ui.html#reviewers[adding reviewers] to a draft
502change the change is made visible to these users. This way you can
503collaborate with other users in privacy.
504
505By pushing to `refs/drafts/<target-branch>` you can also upload draft
506patch sets to non-draft changes. Draft patch sets are immediately
507visible to all reviewers of the change, but other users cannot see the
508draft patch set. A draft patch set can be published and deleted in the
509same way as a draft change.
510
511[[inline-edit]]
512== Inline Edit
513
514It is possible to link:user-inline-edit.html#editing-change[edit
515changes inline] directly in the web UI. This is useful to make small
516corrections immediately and publish them as a new patch set.
517
518It is also possible to link:user-inline-edit.html#create-change[create
519new changes inline].
520
521[[project-administration]]
522== Project Administration
523
524Every project has a link:intro-project-owner.html#project-owner[project
525owner] that administrates the project. Project administration includes
526the configuration of the project
527link:intro-project-owner.html#access-rights[access rights], but project
528owners have many more possibilities to customize the workflows for a
529project which are described in the link:intro-project-owner.html[
530project owner guide].
531
532[[no-code-review]]
533== Working without Code Review
534
535Doing code reviews with Gerrit is optional and you can use Gerrit
536without code review as a pure Git server.
537
538.Push with bypassing Code Review
539----
540 $ git commit
541 $ git push origin HEAD:master
542
543 // this is the same as:
544 $ git commit
545 $ git push origin HEAD:refs/heads/master
546----
547
548[NOTE]
549Bypassing code review must be enabled in the project access rights. The
550project owner must allow it by assigning the
551link:access-control.html#category_push_direct[Push] access right on the
552target branch (`refs/heads/<branch-name>`).
553
554[NOTE]
555If you bypass code review you always need to merge/rebase manually if
556the tip of the destination branch has moved. Please keep this in mind
557if you choose to not work with code review because you think it's
558easier to avoid the additional complexity of the review workflow; it
559might actually not be easier.
560
561[NOTE]
562The project owner may enable link:user-upload.html#auto_merge[
563auto-merge on push] to benefit from the automatic merge/rebase on
564server side while pushing directly into the repository.
565
Martin Fick21c557b2015-08-31 16:03:24 -0600566[[user-refs]]
567== User Refs
568
569User configuration data such as link:#preferences[preferences] is
570stored in the `All-Users` project under a per-user ref. The user's
571ref is based on the user's account id which is an integer. The user
572refs are sharded by the last two digits (`+nn+`) in the refname,
573leading to refs of the format `+refs/users/nn/accountid+`.
574
Edwin Kempin1f556222015-04-22 13:24:39 +0200575[[preferences]]
576== Preferences
577
578There are several options to control the rendering in the Gerrit web UI.
579Users can configure their preferences under `Settings` > `Preferences`.
Martin Fick21c557b2015-08-31 16:03:24 -0600580The user's preferences are stored in a `git config` style file named
581`preferences.config` under the link:#user-refs[user's ref] in the
582`All-Users` project.
Edwin Kempin1f556222015-04-22 13:24:39 +0200583
584The following preferences can be configured:
585
586- [[show-site-header]]`Show Site Header`:
587+
588Whether the site header should be shown.
589
590- [[use-flash]]`Use Flash Clipboard Widget`:
591+
592Whether the Flash clipboard widget should be used. If enabled Gerrit
593offers a copy-to-clipboard icon next to IDs and commands that need to
594be copied frequently, such as the Change-Ids, commit IDs and download
595commands.
596
597- [[cc-me]]`CC Me On Comments I Write`:
598+
599Whether you get notified by email as CC on comments that you write
600yourself.
601
602- [[review-category]]`Display In Review Category`:
603+
604This setting controls how the values of the review labels in change
605lists and dashboards are visualized.
606+
607** `None`:
608+
609For each review label only the voting value is shown. Approvals are
610rendered as a green check mark icon, vetos as a red X icon.
611+
612** `Show Name`:
613+
614For each review label the voting value is shown together with the full
615name of the voting user.
616+
617** `Show Email`:
618+
619For each review label the voting value is shown together with the email
620address of the voting user.
621+
622** `Show Username`:
623+
624For each review label the voting value is shown together with the
625username of the voting user.
626+
627** `Show Abbreviated Name`:
628+
629For each review label the voting value is shown together with the
630initials of the full name of the voting user.
631
632- [[page-size]]`Maximum Page Size`:
633+
634The maximum number of entries that are shown on one page, e.g. used
635when paging through changes, projects, branches or groups.
636
637- [[date-time-format]]`Date/Time Format`:
638+
639The format that should be used to render dates and timestamps.
640
641- [[relative-dates]]`Show Relative Dates In Changes Table`:
642+
643Whether timestamps in change lists and dashboards should be shown as
644relative timestamps, e.g. '12 days ago' instead of absolute timestamps
645such as 'Apr 15'.
646
647- [[change-size-bars]]`Show Change Sizes As Colored Bars`:
648+
649Whether change sizes should be visualized as colored bars. If disabled
650the numbers of added and deleted lines are shown as text, e.g.
651'+297, -63'.
652
653- [[show-change-number]]`Show Change Number In Changes Table`:
654+
655Whether in change lists and dashboards an `ID` column with the numeric
656change IDs should be shown.
657
658- [[mute-common-path-prefixes]]`Mute Common Path Prefixes In File List`:
659+
660Whether common path prefixes in the file list on the change screen
661should be link:user-review-ui.html#repeating-path-segments[grayed out].
662
663- [[diff-view]]`Diff View`:
664+
665Whether the Side-by-Side diff view or the Unified diff view should be
666shown when clicking on a file path in the change screen.
667
668[[my-menu]]
669In addition it is possible to customize the menu entries of the `My`
670menu. This can be used to make the navigation to frequently used
671screens, e.g. configured link:#dashboards[dashboards], quick.
672
673
674GERRIT
675------
676Part of link:index.html[Gerrit Code Review]
677
678SEARCHBOX
679---------