How do you handle a merge conflict conceptually?
Last updated
Conceptually, resolving a conflict means you (the human) make the decision Git couldn't: for each conflicted region you choose ours, theirs, or a hand-crafted combination, then tell Git the conflict is settled and complete the merge.
Understand the three inputs: The common ancestor (base), your version (ours), and the incoming version (theirs): compare against the base to see each side's intent.
Edit to the correct final state: Remove the
<<<<<<</=======/>>>>>>>markers and leave the code as it should actually be, not just picking one side blindly.Mark as resolved and finish:
git addthe file to stage the resolution, thengit commit(orgit merge --continue).Escape hatches:
git merge --abortreturns to the pre-merge state; a mergetool or--conflict=diff3showing the base helps for tricky cases.Then verify: Build and test: Git resolves text, not correctness.
- https://www.youtube.com/watch?v=mUOVNiy3rro
- https://algomaster.io/learn/git/three-way-merge
- https://codeinput.com/blog/git-conflict-revisions
- https://git-scm.com/docs/merge-strategies
- https://www.atlassian.com/git/tutorials/using-branches/git-merge
- https://www.youtube.com/watch?v=BCNZ5Uxctuk
- https://git-scm.com/book/ms/v2/Git-Tools-Advanced-Merging
- https://medium.com/@HelanaBakhsh/merge-strategies-with-git-did-you-say-a-three-way-ebedda9984dd