Rerere for repeated conflict resolution in Git - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
We want to understand how the time to resolve conflicts changes when using Git's rerere feature.
Specifically, how does rerere affect the work needed when the same conflict happens multiple times?
Analyze the time complexity of this Git rerere workflow snippet.
git config --global rerere.enabled true
# Make changes causing a conflict
git merge feature-branch
# Resolve conflict manually
git add conflicted-file
# Commit merge
# Later, if the same conflict appears again:
git merge another-branch
# rerere auto-applies previous resolution
This snippet enables rerere, shows a conflict resolution, and then reuses that resolution automatically if the same conflict appears again.
Look for repeated work done when resolving conflicts.
- Primary operation: Manual conflict resolution by editing files.
- How many times: Once per unique conflict without rerere; multiple times if conflict repeats.
- With rerere: Conflict resolution is recorded once and reused automatically on repeats.
Imagine the number of repeated conflicts grows.
| Number of Repeated Conflicts (n) | Manual Resolutions Needed |
|---|---|
| 1 | 1 |
| 10 | 10 without rerere, 1 with rerere |
| 100 | 100 without rerere, 1 with rerere |
Without rerere, work grows linearly with repeated conflicts. With rerere, work stays almost constant after first resolution.
Time Complexity: O(1) for repeated conflict resolutions with rerere enabled
This means once a conflict is resolved, repeating it takes about the same small effort, no matter how many times it happens.
[X] Wrong: "rerere makes all merges instant and cost-free."
[OK] Correct: rerere only helps with conflicts that are exactly the same; new or different conflicts still need manual work.
Understanding rerere's time complexity shows you how automation can reduce repeated manual work, a key skill in efficient DevOps workflows.
What if rerere was disabled? How would the time complexity for repeated conflict resolution change?
Practice
git rerere in conflict resolution?Solution
Step 1: Understand what rerere stands for
Rerere means "reuse recorded resolution" and helps with repeated conflicts.Step 2: Identify its function in Git
It saves conflict resolutions and applies them automatically if the same conflict happens again.Final Answer:
It remembers how you resolved conflicts before and reuses those resolutions. -> Option BQuick Check:
Rerere = reuse recorded resolution [OK]
- Thinking rerere merges without conflicts
- Believing rerere deletes files
- Assuming rerere backs up the repo
Solution
Step 1: Recall the correct config syntax for rerere
The correct key is "rerere.enabled" with a dot, not "rerere.enable".Step 2: Confirm the global flag placement
The global flag comes immediately after "config" and before the key-value pair.Final Answer:
git config --global rerere.enabled true -> Option AQuick Check:
Correct syntax uses rerere.enabled with --global [OK]
- Using rerere.enable instead of rerere.enabled
- Placing --global after the key-value pair
- Using 'git rerere enable' command which doesn't exist
git status show after the second merge if rerere is enabled?
git config --global rerere.enabled true git checkout feature # merge master with conflicts # resolve conflicts manually and commit git checkout feature # merge master again with same conflicts
Solution
Step 1: Understand rerere behavior on repeated conflicts
When rerere is enabled, it remembers how you fixed conflicts and applies those fixes automatically on the same conflict.Step 2: Analyze the second merge scenario
The second merge has the same conflicts, so rerere applies the previous resolution, avoiding manual conflict fixing.Final Answer:
No conflicts, because rerere applied previous resolutions automatically. -> Option AQuick Check:
Rerere auto-applies fixes on repeated conflicts [OK]
- Expecting conflicts again despite rerere
- Thinking merge will fail with error
- Assuming files get deleted automatically
Solution
Step 1: Understand how rerere records resolutions
Rerere saves conflict resolutions only after you commit the resolved merge.Step 2: Identify why rerere might not apply fixes
If you did not commit the resolution, rerere has no record to reuse, so it cannot auto-apply fixes.Final Answer:
You forgot to commit the conflict resolution the first time. -> Option CQuick Check:
Rerere needs committed resolutions to reuse [OK]
- Assuming rerere works without committing resolutions
- Confusing rerere clearing with enabling
- Thinking local vs global enable affects this issue
Solution
Step 1: Enable rerere globally for all repositories
This ensures rerere is active and can record conflict resolutions anywhere.Step 2: Resolve the conflict once and commit the fix
Rerere records this resolution to reuse it automatically on repeated conflicts.Step 3: Benefit from rerere auto-applying fixes on future merges
This saves time by avoiding repeated manual conflict resolution.Final Answer:
Enable rerere globally, resolve the conflict once and commit, then rerere will auto-apply fixes on future merges. -> Option DQuick Check:
Enable + commit fix = rerere auto-applies [OK]
- Disabling rerere loses automation benefits
- Using rerere only on one branch misses conflicts
- Clearing rerere history removes saved fixes
