交互式 rebase 改完提交顺序或拆分提交后,只看最终 diff 有时不容易发现哪一笔提交被改歪了。Git 自带的 range-diff 可以按提交对比两段历史。
环境:Git 2.25+。先在 rebase 前留个临时分支:
git branch before-rebase
git rebase -i main
git range-diff main..before-rebase main..HEAD
输出会把旧提交和新提交配对,= 表示基本没变,! 表示内容有差异,<、> 则表示某边独有。确认完可以删掉临时分支:
git branch -d before-rebase
它只读取历史,不会改工作区。提交比较多时,比逐个抄 hash 跑 git show 更顺手。