Learning center

Show a reviewer what changed after you rebased

After a rebase, give the reviewer a git range-diff between the reviewed commits and the new ones. A plain diff between the two heads mixes your edits with everything that arrived from the base branch.

Two diffs of the same rebase#

The fixture's branch has two commits, "Spell two" and "Spell eight". The reviewer read it at tag v1. The branch was then rebased onto a main that gained a file, and the second commit was amended.

git diff --stat v1 feat reports two files:

 a     | 2 +-
 other | 1 +

The second file is not the author's work. git range-diff main v1 feat compares commit by commit:

1:  06c0735 = 1:  2098549 Spell two
2:  2b993c4 ! 2:  8eecef4 Spell eight
    @@ a: two
     -8
    -+eight
    ++EIGHT
      9

= marks a commit whose patch is unchanged, and ! marks one that changed. The inner lines are a diff of two patches: -+eight means the old patch added eight, and ++EIGHT means the new one adds EIGHT. Run with Git 2.43.

Give the reviewer the three points#

range-diff BASE OLD NEW needs the old head, and after a force push the branch no longer names it. Write it down before you push:

git rev-parse HEAD          # before the rebase; put this in the comment

The reviewer needs the old commit's objects as well. If their clone still has the reviewed head, they can run the command locally. If not, push the old head to a scratch branch or paste your range-diff output into the review comment.

Read it as a decision#

LineReviewer's decision
=The patch is the same. Review it again only if the new base changes what the patch means
!Read the inner diff
<A reviewed commit has no match in the new series. Ask where its change went
>A new commit. Review it in full

A < and a > next to each other can be one commit that changed a lot. Range-diff pairs commits by how similar their patches are, and --creation-factor controls how much difference it accepts before it treats them as unrelated. Manual

What an equal sign does not cover#

= compares patches. A rebase can keep every patch identical and still change behavior, because the surrounding code moved. Suppose the base branch renamed a setting's unit from seconds to milliseconds in a file the branch never touches. The branch's timeout = 30 is still the same patch, marked =. The check for that is the test run on the new head, and a look at what the base gained in the code the branch calls:

git diff --stat OLD_BASE NEW_BASE -- path/the/branch/depends/on

If the base branch was merged into the feature branch instead of rebased, range-diff is a poor fit, because it does not compare merge commits by default. Compare the branch's diff against each merge base instead.

Worked example#

This example is fictional. A reviewer approved a three-commit change, and the author rebased it over 60 commits from main. The handoff comment lists the old head, the new head and the output: two = and one !. The inner diff shows a resolved conflict in which the author kept the branch's retry count and dropped the one that main had raised that week. The reviewer asks about that single line. A 60-commit diff would have shown the same line among thousands.

Pushing that rebase safely is a separate step. The collection starts at handing over evidence.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading