Amending reviews
Last updated
Last updated
So far weโve discussed the simple case where a review is created and merged, but is not edited. The purpose of having your code reviewed is to solicit suggestions on how it can be improved, so itโs very common to go through one or more rounds of feedback and edits. Letโs continue the example above and assume that after receiving feedback from your reviewer, you wish to make some more changes to review 57.
The simplest way to do this is to modify the files locally, and then run git commit --amend to โamendโ your last commit:
At this point review 57 will be in a โmodifiedโ status, and running plz review will push the new code, creating a new revision, rev 3.
Now you wish to continue building on top of review 57 while we wait for any further feedback. You create a new commit and run plz review to push everything to the remote, creating review 59:
A while later you receive one last round of feedback on review 57. This means that you need to amend commit 70fd803
. This is a little more complicated than the previous example because that commit is not at the top of the stack. To amend commit 70fd803
we need to โdescendโ into the stack, amend the commit, and then โascendโ back to the top of the stack, resolving any conflicts that arise along the way.
There are a number of ways to approach this problem, but for simple changes, the easiest approach is to use git rebase -i to rebase โinteractivelyโ. Rebasing is a rich technique with many variations described elsewhere, but in essence it involves transplanting commits from one base commit onto a different base commit, and optionally resolving conflicts, or otherwise editing the commits sequentially, one at a time.
In this case we wish to edit 70fd803
, and transplant 9bd1906 on top of the result. Running git rebase -i main
shows the following file in an interactive editor:
Editor context during rebase: git opens vim by default. If youโre not familiar with file editing in vim, check out this tutorial to cover the basics.
The first two lines contain the sequence of operations that will operate on the branch specified in the rebase command, in this case main. The final lines of this file contain explanatory comments. Saving the file and quitting will โpickโ commits 70fd803
and 9bd1906
in that order as-is. In other words it will have no effect.
In our case, we wish to โeditโ 70fd803
so replace โpickโ on that line with โeditโ (or โeโ for short), then save and quit to kick off the rebase process. This will output the following:
You can amend the commit now, with
Once you are satisfied with your changes, run
Youโve essentially reverted the state of your local repo to 70fd803 and you can now modify files, run code, etc. Once youโve addressed the review comments you amend that commit and continue the rebase:
Note that the top commit is now also โmodifiedโ because it is based on different code. You can now push new revisions to review 57 and 59 by running plz review and continue the review process.