Skip to content

Use fixup commits during code review #53566

@alevkoy

Description

@alevkoy

Introduction

During code review, when PR authors make changes, they should upload fix-up commits containing those changes instead of changing the existing commits and force-pushing. This will streamline reviewer tasks. Once the review is nominally complete, the reviewer should perform a squash rebase and force-push as usual for merging.

Problem description

Code reviews may go through several rounds of review, in which the author uploads new code to address previous comments, typically by amending their previous commits. Due to limitations of GitHub, it may not be immediately obvious to reviewers which parts of the uploaded code are new to them, so they need to review any files that have changed, usually looking at the entire delta of the PR again. This is particularly burdensome on large PRs with several active reviewers.

Proposed change

Authors should avoid pushing amended commits during code review. Instead, they should push fix-up commits addressing reviewer comments. When reviewers are satisfied, authors should squash in the fix-up commits and force-push prior to final approval and merging.

Detailed RFC

Background

Git's interactive rebase supports squash and fixup operations on commits. squash combines two or more commits into one and combines their commit messages into one. fixup combines the commits into one but only retains the first commit message. "Fix-up commits" or "squash commits" are commits that a user intends to fixup or squash later, typically indicating the base commit onto which the new commit will be fixed up or squashed, e.g.

deadbeef fixup: Declare API # Commit message: Adds comments
2468abab Define API
1234abcd Declare API

Proposed change (Detailed)

  • During code review, authors will avoid pushing amended commits and instead push fix-up commits containing their new changes.
  • Reviewers will review new commits until they are satisfied that the new commits address the concerns they raised about the previous commits.
  • When reviewers have satisfied their concerns, authors will squash the previously created fix-up commits and force-push, retaining the original base commit with git rebase --keep-base.
  • Reviewers will verify that the author did not make any significant changes during this operation, which should be straightforward in GitHub's compare UI. Reviewers will also verify that the overall commit structure is still to their liking. If those things aren't true, review will continue.
  • Reviewers will approve and merge the PR.

Dependencies

I think the blast radius of this is pretty minimal. We could try it on a few PRs and see how it goes before making any policy changes.

Concerns and Unresolved Questions

  • Git has facilities to automate fixup and squash operations like so:

    git commit # Original commit 1234, "Add a feature"
    # Fix formatting
    git commit --fixup=1234 # Create a fix-up commit
    # Now there are two commits
    git rebase --autosquash
    # Now there is just one commit, "Add a feature," with correct formatting
    

    These operations create and rely on commit headlines with the format fixup: Previous headline or squash: Previous headline.

    Authors could use this feature to automate some of the steps. However, this would get in the way of using --autosquash locally on that PR for their own purposes. I think it should be fine if authors use FIXUP: Previous message or similar for the fix-up commits they want to upload for review. The reviewer experience should be the same either way.

  • This process is probably overkill for small PRs of a few lines that are trivial to re-review. I think fix-ups should be recommended for large PRs.

Alternatives

Habitually not rebasing

This proposal primarily addresses weaknesses of GitHub's UI for before-after comparison of force pushes. One annoying behavior is that it will show diffs for every file in the repository, not just those changed by the commits. This makes it basically unusable if the author has rebased the PR. Authors could avoid this by only using git rebase --keep-base during the review. Reviewers would then be able to use GitHub to see just the relatively small changes that the author made in response to review comments.

However, this would retain other weaknesses of the GitHub push comparison UI:

  • It does not show in which commits the new changes will ultimately land.
  • It also does not allow the reviewer to comment in the comparison view, so they need to navigate to a different page with more code and find the code they were looking at previously.
  • It only works for the delta introduced by the latest push. (Actually, I don't know if this is true. I've seen some PRs with multiple compare buttons and some with only one.)

Metadata

Metadata

Assignees

Labels

ProcessTracked by the process WGRFCRequest For Comments: want input from the community

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions