Skip to content

Instantly share code, notes, and snippets.

@jennings
Created August 23, 2024 20:55
Show Gist options
  • Save jennings/9fe1432f394fc18a7eb0c2b2eab8dad3 to your computer and use it in GitHub Desktop.
Save jennings/9fe1432f394fc18a7eb0c2b2eab8dad3 to your computer and use it in GitHub Desktop.
Code reviews should have a single commit
When reviewing code, you should strive to review a single commit per review.
# How do I review a single commit?
If you are using pull requests, the branch you're reviewing should only have one commit to merge into the target branch.
# How do I address review feedback if I can only have one commit in my branch?
Make your changes and _amend_ the commit, then force push with `git push -f`.
# Isn't force pushing dangerous?
If multiple people are collaborating on the same branch, force pushing that branch will interfere with everyone else who uses
that branch. If anyone else bases their work on commits that were overwritten, they will have to rebase their changes.
But in many (most?) organizations, a branch for a pull request is only used by one author:
- Everyone merges pull requets to the _main_ branch.
- Alice creates a branch named _my-feature_ and opens a pull request
- Reviewers leave feedback, Alice updates _my-feature_ to address it.
- Finally, the pull request is completed, merging _my-feature_ into _main_ and deleting it.
In this example, Alice can force push to _my-feature_ without interrupting anyone. No one
started their work on top of _my-feature_.
# Doesn't this mean commits have to be huge?
TODO: Break feature into small commits, each reviewed separately
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment