マージコンフリクトは、Gitが変更を自動的に結合できない場合に発生します(両側が同じ行を修正した場合)。これを解決するには、コンフリクトマーカーを理解し、正しい結果を決定し、マージを完了する必要があります。これを自信を持って行うことは、重要な実践的スキルです。
コンフリクトがいつ、なぜ発生するか
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.
コンフリクトマーカーを理解する
<<<<<<< HEAD
code from YOUR current branch (the one you're merging INTO)
=======
code from the OTHER branch (the one being merged IN)
>>>>>>> feature-branch
→ <<<<<<< 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.
