Video in progress
A colleague rebased a PR after review and force pushed. How do you see what changed without rereading the whole diff?
git range-diff compares the old and new commit series pair by pair: which commit changed, which was added or dropped. I take the old tip from the origin/... reflog; GitHub and GitLab also have "compare with the previous version".
📖 Answer
After a rebase, a plain git diff old new is useless: everything that landed on main in the meantime gets mixed in. range-diff (Git 2.19+) pairs up the commits by content and shows only the differences in the patches themselves.
git fetch
# origin/feature/refund@{1} is the state before the fetch (from the reflog)
git range-diff origin/feature/refund@{1}...origin/feature/refund
The result looks roughly like this:
1: a1b2c3d = 1: f4e5d6c Refund entity
2: b2c3d4e ! 2: e5f6a7b RefundService
@@ RefundService.java
- if (amount.compareTo(paid) > 0) {
+ if (amount.compareTo(paid) >= 0) {
3: c3d4e5f < -: ------- Vaqtinchalik log
-: ------- > 3: d6e7f8a Refund uchun integratsion test
= means unchanged, ! means changed (with a diff of the diff inside), < means removed, and > means a new commit.
With the three-dot form, Git finds the common base of the two versions itself, so even if the branch was moved onto a new main, the changes in main do not get mixed in.
I use this myself after my own rebase too: git range-diff @{u}...HEAD, to check that I did not accidentally lose something before a force push.
Sign up to mark studied questions and save your progress.