合并冲突发生在 Git 无法自动合并更改时(双方都修改了相同的行)。解决冲突涉及理解冲突标记、决定正确的结果,并完成合并。自信地处理这一问题是一项重要的实践技能。
冲突何时以及为何发生
text
Git auto-merges most changes, but a CONFLICT occurs when both branches changed the
SAME LINES (or one deleted what the other modified) — Git can't decide, so it asks YOU.
→ Conflicts are NORMAL in collaboration, not errors — just changes Git can't auto-resolve.
理解冲突标记
text
<<<<<<< HEAD
code from YOUR current branch (the one you're merging INTO)
=======
code from the OTHER branch (the one being merged IN)
>>>>>>> feature-branch
text
→ <<<<<<< to ======= : your side (HEAD)
→ ======= to >>>>>>> : their side
→ You edit to the CORRECT final result (one side, the other, or a COMBINATION),
then REMOVE all the markers.
