Concepts

Git Rerere Deep Dive

Master Git Rerere (reuse recorded resolution): config, workflow integration, storage, and team sharing.

Who This Is For
  • Readers who want the history model before advanced commands
Prerequisites
  • A basic sense that commits are not just a file list
Common Risks
  • Treating a concepts page like a command how-to

What you will learn

  • Understand the core purpose of Git Rerere Deep Dive
  • Master the basic usage and common options of Git Rerere Deep Dive
  • Master Git Rerere (reuse recorded resolution): config, workflow integration, storage, and team sharing.
  • Understand key concepts: Overview
  • Know when to use this feature and when to avoid it

Start with a problem

You've encountered a conceptual question while using Git — you roughly know what it means, but you're not entirely sure about its precise definition and boundaries.

Overview

Rerere = Reuse Recorded Resolution. It makes Git remember how you resolved conflicts, then automatically reuses the resolution next time the same conflict appears.

Enable & Configure

# Global (recommended)
git config --global rerere.enabled true

# Per-repo
git config rerere.enabled true

# Memory cache size (default 1000)
git config --global rerere.maxMemory 1000

# Disk expiry days (default 60)
git config --global rerere.autoupdate true

Key Settings

SettingDefaultDescription
rerere.enabledfalseEnable rerere
rerere.autoupdatefalseAuto-stage resolved conflicts
rerere.maxMemory1000In-memory cache entries
rerere.maxDiskUsage0 (unlimited)Max disk bytes

How It Works

Recording Resolutions

flowchart LR
  A[Merge/rebase conflict] --> B[Manual resolve]
  B --> C[git add marks resolved]
  C --> D[Rerere records: conflict fingerprint -> resolution]
  D --> E[Stored in .git/rr-cache/]

Conflict Fingerprint

Git generates a unique fingerprint from:

  • 3 lines context before/after conflict markers
  • Hash of both sides' content
  • File path

Same fingerprint = same conflict = reusable resolution.

Basic Workflows

Scenario 1: Long-lived Feature Branch Merging Main

# After enable, work normally
git merge main
# Conflict -> resolve -> git add -> git commit
# Rerere records automatically

# Two weeks later merge again
git merge main
# Same conflicts AUTO-RESOLVED! No manual work.

Scenario 2: Repeated Rebases

git rebase main
# Conflict -> resolve -> git rebase --continue
# Resolution recorded

# Later rebase same branch
git rebase main
# Previous resolutions auto-applied

Scenario 3: Cross-branch Cherry-pick

git cherry-pick feature-commit
# Conflict resolved, recorded

# Another branch cherry-picks same commit
git checkout other-branch
git cherry-pick feature-commit
# Auto-reuses resolution

Command Reference

View Records

# List all recorded conflicts
git rerere

# Show resolution for specific file
git rerere diff <file>

# Cache status
git rerere status

Manage Records

# Forget specific file
git rerere forget <file>

# Clear all
git rerere clear

# Show unresolved conflicts
git rerere remaining

Manual Apply/Save

# Manually record (after resolving)
git rerere

# Manually apply (during conflict)
git rerere apply <file>

Team Sharing Rerere Cache

Method 1: Commit to Repo (Not Recommended)

# .git/rr-cache/ should NOT be committed
# Binary cache, not cross-platform/version compatible

Method 2: Shared Init Script (Recommended)

# Repo includes preset resolutions
# scripts/setup-rerere.sh
#!/bin/bash
git config rerere.enabled true
# Restore from shared storage (object store, NFS)
rsync -a shared-rerere-cache/ .git/rr-cache/

Method 3: CI Auto-collection

# .github/workflows/rerere.yml
jobs:
  collect-rerere:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Merge main to collect rerere
        run: |
          git config rerere.enabled true
          git merge origin/main --no-commit || true
          # Conflict resolutions auto-saved
      - name: Upload rerere cache
        uses: actions/upload-artifact@v4
        with:
          name: rerere-cache
          path: .git/rr-cache/

Storage Structure

.git/rr-cache/
├── <hash1>/
│   ├── preimage     # Pre-conflict state
│   ├── postimage    # Resolved state
│   └── thisimage    # Current worktree (for matching)
├── <hash2>/
│   └── ...
└── MERGE_RR        # Current merge's conflict list

Matching Flow

  1. Conflict occurs → compute fingerprint
  2. Look up in rr-cache/
  3. Found → apply postimage to worktree
  4. autoupdate=true → auto git add marks resolved

Advanced Usage

Pre-training Rerere

# Create test conflict scenario
git checkout -b test-conflict main
echo "conflict content" > file.txt
git commit -am "base"

git checkout -b other main
echo "other content" > file.txt
git commit -am "other"

# Force conflict & resolve
git merge test-conflict
# Resolve conflict
git add file.txt
git commit
# Resolution now recorded, shareable with team

With git merge --no-commit

# Preview merge, auto-apply rerere
git merge --no-commit feature
# rerere auto-resolves known conflicts
git status  # See remaining conflicts
git commit

Debug Resolutions

# Show current conflict fingerprint
git rerere diff

# View preimage/postimage
cat .git/rr-cache/<hash>/preimage
cat .git/rr-cache/<hash>/postimage

Best Practices

  1. Enable rerere.enabled=true globally — zero cost, huge payoff
  2. Enable autoupdate — auto-stage resolutions, fewer git add
  3. Essential for long-lived branches — weekly main merges auto-resolve 90%+ conflicts
  4. Team-share preset cache — CI collects, distributes common resolutions
  5. Periodic cleanupgit rerere clear prevents cache bloat

Common Issues

IssueCauseFix
Conflict not auto-resolvedFingerprint mismatch (context changed)Resolve manually once, records
Recorded wrong resolutionCommitted without reviewgit rerere forget <file> to delete
Cache too largeLong-term accumulationSet rerere.maxDiskUsage
Cross-platform failsLine ending/encoding diffStandardize via .gitattributes

Try it yourself

  1. Practice the git-rerere-deep command in a test repository and observe state changes before and after
  2. Experiment with different options and compare the output differences
  3. Simulate a real scenario where you would need to use this, and walk through the full process

Continue Learning

  1. commands/git-rerere — git rerere reference
  2. workflows/rerere-for-recurring-conflicts — Recurring conflict workflow
  3. concepts/git-merge-deep — Git Merge Deep Dive
  4. concepts/git-rebase-deep — Git Rebase Deep Dive