长时间维护分支、反复 rebase 同一批提交时,同一个冲突可能会出现多次。Git 自带的 rerere 会记录一次已经解决的冲突,下次遇到相同冲突时尝试套用。
# 只对当前仓库开启,不改全局配置
git config rerere.enabled true
git rebase main
# 手动编辑冲突文件后检查
git rerere status
git rerere diff
git add path/to/file
git rebase --continue
确认自动套用的结果没问题后再暂存;如果想让 Git 自动更新索引,可以另开 rerere.autoupdate,但我觉得先人工看一眼更稳。记录会放在 .git/rr-cache,不需要提交到仓库。发现某次记录不该复用时,可以用 git rerere forget -- path/to/file 清掉。环境是 Git 2.x,适合经常 rebase 或合并长期分支的仓库。