Effective Git http://eclipse.org/egit http://code.google.com/p/ gerrit Matthias Sohn (SAP) + = Stefan Lay (SAP) Chris Anis...
Git <ul><li>…  a distributed revision control system built by the Linux project to facilitate code review </li></ul><ul><l...
Git at Eclipse <ul><li>Eclipse defined a roadmap to move to Git CVS has been deprecated </li></ul><ul><li>EGit  is an Ecli...
Modern Code Review – What is it ? <ul><ul><li>When one developer writes code, another developer is asked to review that co...
Code Review – Benefits <ul><ul><li>Four eyes catch more bugs </li></ul></ul><ul><ul><ul><li>Catch bugs early to save hours...
Developer PC Gerrit git git git git Developer PC git git Hudson - clone repository  - fetch / push changes - verify propos...
Developer PC git git Gerrit git git git git push improved  change 10 Developer PC git git fetch change 23  to try it maste...
Git Configuration
Git Concepts – config files <ul><ul><li>git config –l </li></ul></ul><ul><ul><li>git config –e </li></ul></ul><ul><ul><li>...
Basic Concepts
Making Changes <ul><ul><li>Structure in the file system </li></ul></ul><ul><ul><li>One working tree per repo </li></ul></u...
Making Changes <ul><ul><li>Checkout:  populate working tree with the commit you want to start working from </li></ul></ul>...
Making Changes <ul><ul><li>Just start doing your changes </li></ul></ul><ul><ul><ul><li>modify, add, delete files </li></u...
Commiting Changes <ul><ul><li>git commit </li></ul></ul><ul><ul><li>Provide a commit message </li></ul></ul><ul><ul><ul><l...
Commits <ul><ul><li>Commit history </li></ul></ul><ul><ul><ul><li>B is successor of A </li></ul></ul></ul><ul><ul><ul><li>...
Branches <ul><ul><li>Branch is a named pointer to a commit </li></ul></ul><ul><ul><li>Commit command moves the pointer </l...
Branches <ul><ul><li>The (branch) pointer can also be moved  “manually” to any commit </li></ul></ul><ul><ul><ul><li>git r...
Branches <ul><ul><li>What happens on next  git commit  ? </li></ul></ul><ul><ul><li>C and D continue to exist but they are...
Branches <ul><ul><li>Usually there are many branches in  a Git repository </li></ul></ul><ul><ul><li>Branches can also be ...
HEAD <ul><ul><li>HEAD – pointer to a branch </li></ul></ul><ul><ul><li>Means:  “Current Branch” – the branch which you hav...
Cloning & Fetching
Clone Remote Repository <ul><ul><li>Git is a distributed versioning system </li></ul></ul><ul><ul><ul><li>git clone <remot...
Clone Remote Repository <ul><ul><li>Remote tracking branches, full names:  </li></ul></ul><ul><ul><ul><li>remotes/origin/m...
Remote Tracking Branches <ul><ul><li>Just like any other branch, but read-only </li></ul></ul><ul><ul><ul><li>possible: gi...
Fetch <ul><ul><li>git fetch  will update all remote tracking branches to reflect the changes done in the  “origin” repo </...
Fetch <ul><ul><li>Always safe to do </li></ul></ul><ul><ul><li>Updates only remote tracking branches </li></ul></ul><ul><u...
Merge & Rebase
Merge <ul><ul><li>git merge feature-1 </li></ul></ul><ul><ul><ul><li>will replay all changes done in feature-1  since it d...
Merge <ul><ul><li>Easy Case - Fast Forward </li></ul></ul><ul><ul><ul><li>git merge feature-1 </li></ul></ul></ul><ul><ul>...
Git Concepts – Cherry Pick <ul><ul><li>git cherry-pick F </li></ul></ul><ul><ul><ul><li>applies changes introduced by F, m...
Git Concepts - Rebase <ul><ul><li>Alternative to Merge - Keeping history linear </li></ul></ul><ul><ul><li>git rebase 1.0 ...
Pushing
Push <ul><ul><li>git push origin HEAD:master </li></ul></ul><ul><ul><li>From local to remote repository </li></ul></ul><ul...
Push <ul><ul><li>Which commits get pushed? </li></ul></ul><ul><ul><li>ALL commits from the local branch not available in t...
Push <ul><ul><li>Remote branch has changed </li></ul></ul><ul><ul><ul><li>git push will fail because fast forward is not p...
Git Concepts - Push <ul><ul><li>Possibility One </li></ul></ul><ul><ul><ul><li>pull (fetch + merge), push </li></ul></ul><...
Push <ul><ul><li>Possibility Two </li></ul></ul><ul><ul><ul><li>fetch, rebase, push </li></ul></ul></ul>A B origin/master ...
Push <ul><ul><li>Which graph do you like more ? </li></ul></ul>A B D master Remote  “origin” repo C E A B D master C ’ Rem...
Gerrit Concepts
Push <ul><ul><li>Push to Gerrit is the same like push to Git </li></ul></ul><ul><ul><ul><li>with one Gerrit speciality:  r...
Push <ul><ul><li>It seems like every push to Gerrit goes to the same branch  refs/for/master </li></ul></ul><ul><ul><li>Ho...
Push <ul><ul><li>git push origin HEAD:refs/for/master </li></ul></ul>A B origin/master C Local repo feature-1 HEAD A B C m...
Push <ul><ul><li>What if feature branch has 2 commits ? </li></ul></ul><ul><ul><li>Remember Git semantics for Push? </li><...
Changes <ul><ul><li>Change consists of </li></ul></ul><ul><ul><ul><li>Change ID (important!) </li></ul></ul></ul><ul><ul><...
New Change vs New Patch Set <ul><ul><li>How does Gerrit know whether to create a new Change or a new Patch Set for an exis...
New Change vs New Patch Set <ul><ul><li>Example Commit Message with Change-Id: </li></ul></ul>Make lib.Repository abstract...
Push New Patchset <ul><ul><li>No  dependencies between Patchsets </li></ul></ul><ul><ul><ul><li>can ’t push a successor co...
Push New Patchset <ul><ul><li>If you pushed C and need to replace it by a new commit as a new patchset use </li></ul></ul>...
Push New Patch Set <ul><ul><li>A Common Mistake </li></ul></ul><ul><ul><ul><li>author of the Patch Set 1 is not available ...
Push New Patchset <ul><ul><li>A Common Mistake </li></ul></ul><ul><ul><ul><li>git pull origin refs/changes/66/366/1 </li><...
Push New Patch Set <ul><ul><li>The right way: </li></ul></ul><ul><ul><ul><li>fetch  (don ’t pull) </li></ul></ul></ul><ul>...
Push New Patchset <ul><ul><li>The right way: </li></ul></ul><ul><ul><ul><li>commit D is not successor of C </li></ul></ul>...
Review and Vote <ul><ul><li>Show in Gerrit Web UI </li></ul></ul><ul><ul><li>Voting the lowest mark means Veto </li></ul><...
Fetch Open Change Locally <ul><ul><li>Don ’t forget that every patchset is a commit </li></ul></ul><ul><ul><li>Use  git fe...
Best Practices <ul><ul><li>Create local branch for each feature or bugfix you work on </li></ul></ul><ul><ul><ul><li>branc...
Best Practices <ul><ul><li>Push finished features only </li></ul></ul><ul><ul><ul><li>who wants to review non finished fea...
Best Practices <ul><ul><li>Write good commit message </li></ul></ul><ul><ul><ul><li>First line is summary </li></ul></ul><...
Upcoming SlideShare
Loading in...5
×

Effective Git with Eclipse

7,048

Published on

An introduction to Git and Gerrit and how the eclipse.org ecosystem plans to use Gerrit for code reviews.

Effective Git with Eclipse

  1. 1. Effective Git http://eclipse.org/egit http://code.google.com/p/ gerrit Matthias Sohn (SAP) + = Stefan Lay (SAP) Chris Aniszczyk(Redhat) Shawn Pearce (Google)
  2. 2. Git <ul><li>… a distributed revision control system built by the Linux project to facilitate code review </li></ul><ul><li>Distributed means no central repository </li></ul><ul><ul><li>No central authority! </li></ul></ul><ul><ul><li>Easy offline usage </li></ul></ul><ul><ul><li>Easy to branch a project </li></ul></ul><ul><ul><li>Protected against manipulation by cryptographic hashes </li></ul></ul><ul><li>Really good at merging </li></ul><ul><ul><li>Coordination only needed &quot;after the fact ” </li></ul></ul><ul><ul><li>Easier to rejoin (or refresh) branches </li></ul></ul><ul><li>Structured around commits (i.e. patches) </li></ul><ul><ul><li>Tools for identifying problem commits (git bisect) </li></ul></ul><ul><ul><li>Tools for restructuring branches w/ specific commits </li></ul></ul>
  3. 3. Git at Eclipse <ul><li>Eclipse defined a roadmap to move to Git CVS has been deprecated </li></ul><ul><li>EGit is an Eclipse Team provider for Git </li></ul><ul><ul><li>http://www.eclipse.org/egit/ </li></ul></ul><ul><li>JGit is a lightweight Java library implementing Git </li></ul><ul><ul><li>http://www.eclipse.org/jgit/ </li></ul></ul><ul><li>The goal is to build an Eclipse community around Git. </li></ul><ul><li>EGit/JGit are still beta and we want to establish a feedback loop to improve the tooling. </li></ul>
  4. 4. Modern Code Review – What is it ? <ul><ul><li>When one developer writes code, another developer is asked to review that code </li></ul></ul><ul><ul><li>A careful line-by-line critique </li></ul></ul><ul><ul><li>Happens in a non-threatening context </li></ul></ul><ul><ul><li>Goal is cooperation, not fault-finding </li></ul></ul><ul><ul><li>Integral part of coding process </li></ul></ul><ul><ul><li>Otherwise this will happen: </li></ul></ul><ul><ul><li>Debugging someone else's broken code </li></ul></ul><ul><ul><li>– Involuntary code review: Not so good; emotions may flare </li></ul></ul>Guido van Rossum [1] [1] http://code.google.com/p/rietveld/downloads/detail?name=Mondrian2006.pdf
  5. 5. Code Review – Benefits <ul><ul><li>Four eyes catch more bugs </li></ul></ul><ul><ul><ul><li>Catch bugs early to save hours of debugging </li></ul></ul></ul><ul><ul><li>Mentoring of new developers / contributors </li></ul></ul><ul><ul><ul><li>Learn from mistakes without breaking stuff </li></ul></ul></ul><ul><ul><li>Establish trust relationships </li></ul></ul><ul><ul><ul><li>Prepare for more delegation </li></ul></ul></ul><ul><ul><li>Good alternative to pair programming </li></ul></ul><ul><ul><ul><li>asynchronous and across locations </li></ul></ul></ul><ul><ul><li>Coding standards </li></ul></ul><ul><ul><ul><li>Keep overall readability & code quality high </li></ul></ul></ul>Guido van Rossum [1] [1] http://code.google.com/p/rietveld/downloads/detail?name =Mondrian2006.pdf
  6. 6. Developer PC Gerrit git git git git Developer PC git git Hudson - clone repository - fetch / push changes - verify proposed changes - continuous integration builds
  7. 7. Developer PC git git Gerrit git git git git push improved change 10 Developer PC git git fetch change 23 to try it master change 12 change 10 change 23 submit accepted change 12 fetch master to get updates
  8. 8. Git Configuration
  9. 9. Git Concepts – config files <ul><ul><li>git config –l </li></ul></ul><ul><ul><li>git config –e </li></ul></ul><ul><ul><li>--system </li></ul></ul><ul><ul><li>--global </li></ul></ul>System <gitinst>/etc/gitconfig Global ~/.gitconfig Repository Specific .git/config
  10. 10. Basic Concepts
  11. 11. Making Changes <ul><ul><li>Structure in the file system </li></ul></ul><ul><ul><li>One working tree per repo </li></ul></ul><ul><ul><li>.git folder is the Git repo </li></ul></ul><ul><ul><li>Files/folders under the parent of .git are the working tree </li></ul></ul>
  12. 12. Making Changes <ul><ul><li>Checkout: populate working tree with the commit you want to start working from </li></ul></ul><ul><ul><ul><li>most of the time you will checkout a branch </li></ul></ul></ul><ul><ul><ul><li> checkout the commit pointed to by the branch (aka: tip of the branch) </li></ul></ul></ul><ul><ul><ul><li>per file checkout means revert ! </li></ul></ul></ul>Calculator .git <working tree> git checkout master
  13. 13. Making Changes <ul><ul><li>Just start doing your changes </li></ul></ul><ul><ul><ul><li>modify, add, delete files </li></ul></ul></ul><ul><ul><li>Tell Git which changes you intend to commit </li></ul></ul><ul><ul><ul><li>git add </li></ul></ul></ul><ul><ul><ul><li>EGit helps by auto-detecting what you changed </li></ul></ul></ul>
  14. 14. Commiting Changes <ul><ul><li>git commit </li></ul></ul><ul><ul><li>Provide a commit message </li></ul></ul><ul><ul><ul><li>First line is header </li></ul></ul></ul><ul><ul><ul><li>separated by a blank line follows the body </li></ul></ul></ul><ul><ul><ul><li>last paragraph is for meta data in key: value format </li></ul></ul></ul><ul><ul><li>commit represents a version of the complete repository </li></ul></ul><ul><ul><li>commits are identified by a globally unique ID (SHA1) </li></ul></ul><ul><ul><li>If two Git repos both contain a commit with the same ID then the content in these two commits is identical </li></ul></ul>
  15. 15. Commits <ul><ul><li>Commit history </li></ul></ul><ul><ul><ul><li>B is successor of A </li></ul></ul></ul><ul><ul><ul><li>C is successor of B </li></ul></ul></ul>A B C
  16. 16. Branches <ul><ul><li>Branch is a named pointer to a commit </li></ul></ul><ul><ul><li>Commit command moves the pointer </li></ul></ul>A B C master A B C master D commit
  17. 17. Branches <ul><ul><li>The (branch) pointer can also be moved “manually” to any commit </li></ul></ul><ul><ul><ul><li>git reset </li></ul></ul></ul>A B C master D A B C master D reset B
  18. 18. Branches <ul><ul><li>What happens on next git commit ? </li></ul></ul><ul><ul><li>C and D continue to exist but they are not in the history or the master branch </li></ul></ul>A B C master D A B C master D E commit
  19. 19. Branches <ul><ul><li>Usually there are many branches in a Git repository </li></ul></ul><ul><ul><li>Branches can also be deleted </li></ul></ul>A B C origin/master D E feature 1 F bugfix 15 G feature 2
  20. 20. HEAD <ul><ul><li>HEAD – pointer to a branch </li></ul></ul><ul><ul><li>Means: “Current Branch” – the branch which you have checked out </li></ul></ul>A B C D E feature 1 F bugfix 15 HEAD origin/master
  21. 21. Cloning & Fetching
  22. 22. Clone Remote Repository <ul><ul><li>Git is a distributed versioning system </li></ul></ul><ul><ul><ul><li>git clone <remote-repo> </li></ul></ul></ul><ul><ul><ul><li>cloned repo gets local name “origin” (by default) </li></ul></ul></ul>A B C master D E F HEAD feature-1 A B C master D E F HEAD origin/feature-1 origin/master Remote “origin” Local clone clone
  23. 23. Clone Remote Repository <ul><ul><li>Remote tracking branches, full names: </li></ul></ul><ul><ul><ul><li>remotes/origin/master </li></ul></ul></ul><ul><ul><ul><li>remotes/origin/feature-1 </li></ul></ul></ul>A B C master D E F HEAD origin/feature-1 origin/master Local clone
  24. 24. Remote Tracking Branches <ul><ul><li>Just like any other branch, but read-only </li></ul></ul><ul><ul><ul><li>possible: git checkout origin/feature1 </li></ul></ul></ul><ul><ul><ul><li>However, HEAD gets detached! </li></ul></ul></ul>A B C master D E F HEAD origin/feature-1 origin/master
  25. 25. Fetch <ul><ul><li>git fetch will update all remote tracking branches to reflect the changes done in the “origin” repo </li></ul></ul>A B C master D E F HEAD feature-1 Remote “origin” G feature-1 A B C master D E F HEAD origin/feature-1 origin/master Local clone G origin/feature-1 fetch
  26. 26. Fetch <ul><ul><li>Always safe to do </li></ul></ul><ul><ul><li>Updates only remote tracking branches </li></ul></ul><ul><ul><li>Does never change local branches </li></ul></ul>
  27. 27. Merge & Rebase
  28. 28. Merge <ul><ul><li>git merge feature-1 </li></ul></ul><ul><ul><ul><li>will replay all changes done in feature-1 since it diverged from 1.0 (E and F) </li></ul></ul></ul>A B C D E F HEAD feature-1 A B C 1.0 D E F HEAD feature-1 G 1 2 1 2 1.0 merge feature-1
  29. 29. Merge <ul><ul><li>Easy Case - Fast Forward </li></ul></ul><ul><ul><ul><li>git merge feature-1 </li></ul></ul></ul><ul><ul><ul><li>no new commit, just move the pointer </li></ul></ul></ul>A B E HEAD feature-1 A B E HEAD feature-1 1.0 1.0 merge feature-1
  30. 30. Git Concepts – Cherry Pick <ul><ul><li>git cherry-pick F </li></ul></ul><ul><ul><ul><li>applies changes introduced by F, means delta-2 </li></ul></ul></ul><ul><ul><ul><li>no merge relation </li></ul></ul></ul>A B C 1.0 D E F HEAD feature-1 1 2 A B C 1.0 D E F HEAD feature-1 G 2 cherry-pick F
  31. 31. Git Concepts - Rebase <ul><ul><li>Alternative to Merge - Keeping history linear </li></ul></ul><ul><ul><li>git rebase 1.0 </li></ul></ul><ul><ul><li>after rebase fast-forward possible! </li></ul></ul>A B C 1.0 D E F HEAD feature-1 A B C 1.0 D E ’ F ’ HEAD feature-1 1 2 1 2 rebase 1.0
  32. 32. Pushing
  33. 33. Push <ul><ul><li>git push origin HEAD:master </li></ul></ul><ul><ul><li>From local to remote repository </li></ul></ul><ul><ul><ul><li>more precisely: from a local to a remote branch </li></ul></ul></ul>A B origin/master C Local repo feature-1 HEAD A B C master Remote “origin” repo push
  34. 34. Push <ul><ul><li>Which commits get pushed? </li></ul></ul><ul><ul><li>ALL commits from the local branch not available in the remote branch </li></ul></ul>A B origin/master C Local repo feature-1 HEAD D A B C master D Remote “origin” repo push
  35. 35. Push <ul><ul><li>Remote branch has changed </li></ul></ul><ul><ul><ul><li>git push will fail because fast forward is not possible </li></ul></ul></ul>A B origin/master C Local repo feature-1 HEAD A B D master Remote “origin” repo push
  36. 36. Git Concepts - Push <ul><ul><li>Possibility One </li></ul></ul><ul><ul><ul><li>pull (fetch + merge), push </li></ul></ul></ul>A B origin/master C Local repo feature-1 HEAD A B D master Remote “origin” repo D E C E push
  37. 37. Push <ul><ul><li>Possibility Two </li></ul></ul><ul><ul><ul><li>fetch, rebase, push </li></ul></ul></ul>A B origin/master Local repo feature-1 HEAD D C ’ A B D master Remote “origin” repo C ’ push
  38. 38. Push <ul><ul><li>Which graph do you like more ? </li></ul></ul>A B D master Remote “origin” repo C E A B D master C ’ Remote “origin” repo
  39. 39. Gerrit Concepts
  40. 40. Push <ul><ul><li>Push to Gerrit is the same like push to Git </li></ul></ul><ul><ul><ul><li>with one Gerrit speciality: refs/for in the target branch name </li></ul></ul></ul><ul><ul><li>Compare: </li></ul></ul><ul><ul><ul><li>Push to Git: git push origin HEAD:master </li></ul></ul></ul><ul><ul><ul><li>Push to Gerrit: git push origin HEAD: refs/for /master </li></ul></ul></ul>
  41. 41. Push <ul><ul><li>It seems like every push to Gerrit goes to the same branch refs/for/master </li></ul></ul><ul><ul><li>However, Gerrit tricks your git client: </li></ul></ul><ul><ul><ul><li>it creates a new branch for the commit(s) you push </li></ul></ul></ul><ul><ul><ul><li>and creates a new open Gerrit change containing the pushed commit </li></ul></ul></ul>
  42. 42. Push <ul><ul><li>git push origin HEAD:refs/for/master </li></ul></ul>A B origin/master C Local repo feature-1 HEAD A B C master Gerrit hosted “origin” repo refs/changes/63/363/1 Gerrit DB - Open Changes: … {Change-ID = 1234, Patch-Set-1 = refs/changes/63/363/1 } …
  43. 43. Push <ul><ul><li>What if feature branch has 2 commits ? </li></ul></ul><ul><ul><li>Remember Git semantics for Push? </li></ul></ul><ul><ul><ul><li>ALL commits from the local branch not available in the remote branch  2 changes in Gerrit ! </li></ul></ul></ul>A B origin/master C Local repo feature-1 HEAD D A B C master Gerrit hosted “origin” repo refs/changes/63/363/1, Change 1234 D refs/changes/64/364/1, Change 1235 depends on
  44. 44. Changes <ul><ul><li>Change consists of </li></ul></ul><ul><ul><ul><li>Change ID (important!) </li></ul></ul></ul><ul><ul><ul><li>metadata (owner, project, etc..) </li></ul></ul></ul><ul><ul><ul><li>one or more patch-sets </li></ul></ul></ul><ul><ul><ul><li>comments </li></ul></ul></ul><ul><ul><ul><li>votes </li></ul></ul></ul><ul><ul><li>Patch Set represents a Git Commit </li></ul></ul>
  45. 45. New Change vs New Patch Set <ul><ul><li>How does Gerrit know whether to create a new Change or a new Patch Set for an existing change? </li></ul></ul><ul><ul><li>It looks at the Commit Message and searches for String “Change-Id: <ISHA1>” in the last paragraph of the commit message </li></ul></ul><ul><ul><li>If found it will create a new patchset for this changes, otherwise it will create a new change </li></ul></ul>
  46. 46. New Change vs New Patch Set <ul><ul><li>Example Commit Message with Change-Id: </li></ul></ul>Make lib.Repository abstract and lib.FileRepository its implementation To support other storage models other than just the local filesystem, … will rename it into storage.file.FileRepository, but to do that we need to also move a number of other related class, which we aren't quite ready to do. Change-Id: I1bd54ea0500337799a8e792874c272eb14d555f7 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
  47. 47. Push New Patchset <ul><ul><li>No dependencies between Patchsets </li></ul></ul><ul><ul><ul><li>can ’t push a successor commit as the next patchset </li></ul></ul></ul><ul><ul><ul><li>commit D can ’t be Patch Set 2 of change 1234 </li></ul></ul></ul>A B origin/master C Local repo feature-1 HEAD D Change 1234, Patch Set 1
  48. 48. Push New Patchset <ul><ul><li>If you pushed C and need to replace it by a new commit as a new patchset use </li></ul></ul><ul><ul><ul><li>git commit –amend </li></ul></ul></ul><ul><ul><ul><li>with –amend option the new commit replaces the current instead of becoming successor </li></ul></ul></ul>A B origin/master C Local repo feature-1 HEAD Change 1234, Patch Set 1 A B origin/master C Local repo feature-1 HEAD D Change 1234, Patch Set 1
  49. 49. Push New Patch Set <ul><ul><li>A Common Mistake </li></ul></ul><ul><ul><ul><li>author of the Patch Set 1 is not available and somebody else needs to continue and provide Patch Set 2 </li></ul></ul></ul><ul><ul><ul><li>use git pull to get the Patch Set 1 into a local branch </li></ul></ul></ul><ul><ul><ul><li>Fix issues in commit </li></ul></ul></ul><ul><ul><ul><li>Push (including the same Change-Id) </li></ul></ul></ul><ul><ul><ul><li>Gerrit rejects! </li></ul></ul></ul>
  50. 50. Push New Patchset <ul><ul><li>A Common Mistake </li></ul></ul><ul><ul><ul><li>git pull origin refs/changes/66/366/1 </li></ul></ul></ul><ul><ul><ul><li>D is successor of C and cannot be Patch Set 2 </li></ul></ul></ul>A B Local repo HEAD A B C Local repo Change 1234, Patchset 1 master D HEAD master
  51. 51. Push New Patch Set <ul><ul><li>The right way: </li></ul></ul><ul><ul><ul><li>fetch (don ’t pull) </li></ul></ul></ul><ul><ul><ul><li>create a new branch based on the fetched patchset 1 </li></ul></ul></ul><ul><ul><ul><li>fix the issue </li></ul></ul></ul><ul><ul><ul><li>commit –amend </li></ul></ul></ul><ul><ul><ul><li>push </li></ul></ul></ul>
  52. 52. Push New Patchset <ul><ul><li>The right way: </li></ul></ul><ul><ul><ul><li>commit D is not successor of C </li></ul></ul></ul><ul><ul><ul><li>D can become patchset 2 </li></ul></ul></ul>A B C Local repo Change 1234, Patch Set 1 D HEAD feature-1 A B C Local repo Change 1234, Patch Set 1 HEAD feature-1
  53. 53. Review and Vote <ul><ul><li>Show in Gerrit Web UI </li></ul></ul><ul><ul><li>Voting the lowest mark means Veto </li></ul></ul><ul><ul><li>Highest marks in all voting categories needed for change to be merged </li></ul></ul>
  54. 54. Fetch Open Change Locally <ul><ul><li>Don ’t forget that every patchset is a commit </li></ul></ul><ul><ul><li>Use git fetch to fetch it locally if you want to play with it </li></ul></ul><ul><ul><li>Hudson Gerrit plugin does just that ! </li></ul></ul><ul><ul><li>Gerrit creates fetch command for you </li></ul></ul><ul><ul><ul><li>show in Web UI </li></ul></ul></ul>
  55. 55. Best Practices <ul><ul><li>Create local branch for each feature or bugfix you work on </li></ul></ul><ul><ul><ul><li>branch name tells you what your intention was </li></ul></ul></ul><ul><ul><ul><li>less likely you will mix two features in the same branch </li></ul></ul></ul><ul><ul><ul><li>you can have many feature branches at a time </li></ul></ul></ul><ul><ul><ul><li>and switch between them </li></ul></ul></ul>
  56. 56. Best Practices <ul><ul><li>Push finished features only </li></ul></ul><ul><ul><ul><li>who wants to review non finished feature ? </li></ul></ul></ul><ul><ul><ul><li>who wants non-finished features in history ? </li></ul></ul></ul><ul><ul><li>Push complete feature as one commit </li></ul></ul><ul><ul><ul><li>even if you created many commits squash them into one before push </li></ul></ul></ul><ul><ul><ul><li>otherwise you create one change in Gerrit per each commit ! </li></ul></ul></ul><ul><ul><ul><li>use multiple changes if feature can be split into smaller logical units and use last change to switch on the new feature </li></ul></ul></ul>
  57. 57. Best Practices <ul><ul><li>Write good commit message </li></ul></ul><ul><ul><ul><li>First line is summary </li></ul></ul></ul><ul><ul><ul><li>Empty line between paragraphs </li></ul></ul></ul><ul><ul><ul><li>Explain WHY you did the change not WHAT you did (this is visible from the commit) </li></ul></ul></ul><ul><ul><li>Prefer many small changes to one big </li></ul></ul><ul><ul><ul><li>still each small change must be logically complete </li></ul></ul></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×