Skip to content

Latest commit

 

History

History
79 lines (55 loc) · 2.24 KB

File metadata and controls

79 lines (55 loc) · 2.24 KB

Episode 4: Git Rerere 🧠

The hidden gem: Git remembers how you resolved conflicts and auto-applies the same resolution next time.

The Problem

You resolved a merge conflict between feature-A and main. Now you rebase, and... the same conflict appears again. You resolve it identically. Again. And again every time you rebase.

git rerere = Reuse Recorded Resolution. Git memorizes your conflict resolutions and replays them automatically.

Enable It (Do This Once)

git config --global rerere.enabled true

That's it. From now on, Git silently records every conflict resolution you make.

How It Works

  1. Record: When you resolve a conflict and commit, Git stores the before/after of the conflicted hunks.
  2. Replay: Next time the same conflict appears (same conflicting lines), Git auto-resolves it.
  3. You verify: Git applies the resolution but doesn't auto-commit — you review and confirm.

When Is This Useful?

  • Long-lived feature branches that you rebase onto main regularly.
  • Topic branch workflows where you merge/rebase often.
  • "Redo" merges — undo a merge, rework, re-merge without re-resolving.
  • Maintaining multiple release branches with shared cherry-picks.

Key Commands

# Enable rerere
git config --global rerere.enabled true

# See current recorded resolutions
git rerere status

# See the diff of what rerere would apply
git rerere diff

# Forget a specific resolution (if it was wrong)
git rerere forget <path>

# Clear all recorded resolutions
git rerere clear

The Workflow

# First time: merge with conflict
git merge feature-x
# ... resolve conflicts manually ...
git add .
git commit
# rerere silently records the resolution

# Later: undo and redo the merge
git reset --hard HEAD~1
git merge feature-x
# rerere auto-applies your previous resolution!
# Just verify and commit

Pro Tips

  • Always enable rerere globally. There's no downside.
  • If a recorded resolution was wrong, use git rerere forget <file> to clear it.
  • Rerere data lives in .git/rr-cache/ — it's local only.
  • Combine with interactive rebase: rerere handles repeated conflicts during rebase.

Run the Demo

bash episodes/demos/04-rerere-demo.sh