Merge conflicts that keep behavior: resolve with tests
Updated

Resolve conflicts by behavior, not by lines: run the tests before and after, keep both intentions visible.
Conflict markers show lines; the real conflict is intentions. Two branches changed the same code for different reasons, and picking lines at random keeps neither reason. Resolve by behavior: understand both, combine, prove with tests.
Both intentions, then tests
Read both sides first. What was each branch trying to do? The answer is in commit messages and tests, not in the markers.
Combine, do not choose. Keep both behaviors working where they do not contradict; where they contradict, decide explicitly and write why.
Test the combination. The merged result runs the full relevant suite plus a new test for the feared behavior. Green means resolved; red means you misunderstood a side.
Worked example: a fictional checkout conflict
The context below is fictional. Two ParcelTrack branches (fictional) touch fee calculation: one adds a discount, one adds a surcharge. Markers offer a coin flip.
The resolver reads both tests, keeps both rules with explicit precedence, and adds a combined test with both discount and surcharge. Green suite, both behaviors alive, precedence documented.
Checklist: a merge that holds
- Both intentions understood from commits and tests.
- Combination decided explicitly, not by marker order.
- New test guards the feared behavior.
- Full relevant suite green after resolution.
Related reading
- Hands on: Conflict Preserving Behavior.
- The branching companion: Git branching that survives incidents.
Straight answers
Frequently asked questions
Take mine or theirs?
Neither blindly. Read both intentions, combine them, and let the tests judge the result.
Tests pass but I am unsure?
Add a test for the behavior you feared losing, then merge. Uncertainty is a missing test wearing a conflict costume.
How do I prevent monster conflicts?
Small frequent merges. A week-old branch conflicts with everything; a day-old branch conflicts with little.