README.git-cl.codereview 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. The git-cl README describes the git-cl command set. This document
  2. describes how code review and git work together in general, intended
  3. for people familiar with git but unfamiliar with the code review
  4. process supported by Rietveld.
  5. == Concepts and terms
  6. A Rietveld review is for discussion of a single change or patch. You
  7. upload a proposed change, the reviewer comments on your change, and
  8. then you can upload a revised version of your change. Rietveld stores
  9. the history of uploaded patches as well as the comments, and can
  10. compute diffs in between these patches. The history of a patch is
  11. very much like a small branch in git, but since Rietveld is
  12. VCS-agnostic the concepts don't map perfectly. The identifier for a
  13. single review+patches+comments in Rietveld is called an "issue".
  14. Rietveld provides a basic uploader that understands git. This program
  15. is used by git-cl, and is included in the git-cl repo as upload.py.
  16. == Basic interaction with git
  17. The fundamental problem you encounter when you try to mix git and code
  18. review is that with git it's nice to commit code locally, while during
  19. a code review you're often requested to change something about your
  20. code. There are a few different ways you can handle this workflow
  21. with git:
  22. 1) Rewriting a single commit. Say the origin commit is O, and you
  23. commit your initial work in a commit A, making your history like
  24. O--A. After review comments, you commit --amend, effectively
  25. erasing A and making a new commit A', so history is now O--A'.
  26. (Equivalently, you can use git reset --soft or git rebase -i.)
  27. 2) Writing follow-up commits. Initial work is again in A, and after
  28. review comments, you write a new commit B so your history looks
  29. like O--A--B. When you upload the revised patch, you upload the
  30. diff of O..B, not A..B; you always upload the full diff of what
  31. you're proposing to change.
  32. The Rietveld patch uploader just takes arguments to "git diff", so
  33. either of the above workflows work fine. If all you want to do is
  34. upload a patch, you can use the upload.py provided by Rietveld with
  35. arguments like this:
  36. upload.py --server server.com <args to "git diff">
  37. The first time you upload, it creates a new issue; for follow-ups on
  38. the same issue, you need to provide the issue number:
  39. upload.py --server server.com --issue 1234 <args to "git diff">
  40. == git-cl to the rescue
  41. git-cl simplifies the above in the following ways:
  42. 1) "git cl config" puts a persistent --server setting in your .git/config.
  43. 2) The first time you upload an issue, the issue number is associated with
  44. the current *branch*. If you upload again, it will upload on the same
  45. issue. (Note that this association is tied to a branch, not a commit,
  46. which means you need a separate branch per review.)
  47. 3) If your branch is "tracking" (in the "git checkout --track" sense)
  48. another one (like origin/master), calls to "git cl upload" will
  49. diff against that branch by default. (You can still pass arguments
  50. to "git diff" on the command line, if necessary.)
  51. In the common case, this means that calling simply "git cl upload"
  52. will always upload the correct diff to the correct place.
  53. == Patch series
  54. The above is all you need to know for working on a single patch.
  55. Things get much more complicated when you have a series of commits
  56. that you want to get reviewed. Say your history looks like
  57. O--A--B--C. If you want to upload that as a single review, everything
  58. works just as above.
  59. But what if you upload each of A, B, and C as separate reviews?
  60. What if you then need to change A?
  61. 1) One option is rewriting history: write a new commit A', then use
  62. git rebase -i to insert that diff in as O--A--A'--B--C as well as
  63. squash it. This is sometimes not possible if B and C have touched
  64. some lines affected by A'.
  65. 2) Another option, and the one espoused by software like topgit, is for
  66. you to have separate branches for A, B, and C, and after writing A'
  67. you merge it into each of those branches. (topgit automates this
  68. merging process.) This is also what is recommended by git-cl, which
  69. likes having different branch identifiers to hang the issue number
  70. off of. Your history ends up looking like:
  71. O---A---B---C
  72. \ \ \
  73. A'--B'--C'
  74. Which is ugly, but it accurately tracks the real history of your work, can
  75. be thrown away at the end by committing A+A' as a single "squash" commit.
  76. In practice, this comes up pretty rarely. Suggestions for better workflows
  77. are welcome.