3-way merge: khi merge 2 branches, git dùng 3 snapshots:
1. Base (common ancestor): commit nơi 2 branches diverge
2. Ours (current branch HEAD)
3. Theirs (branch đang merge vào)
Git auto-resolve khi: thay đổi ở 2 branches không chạm cùng vùng code — git lấy thay đổi từ cả hai.
Conflict xảy ra khi: cả 2 sides thay đổi cùng dòng, hoặc 1 side delete file mà side kia modify.
Conflict markers:
<<<<<<< HEAD
console.log("our change")
=======
console.log("their change")
>>>>>>> feature/loginManual resolve: xóa markers, giữ đúng code, git add <file>, git merge --continue.
Chiến lược merge:
git merge -X ours feature/login # ưu tiên our side khi conflict
git merge -X theirs feature/login # ưu tiên their side
# Dùng thận trọng — có thể silently mất codeKhi nào dùng ours/theirs strategy: merge release branch về main khi biết chắc 1 side luôn đúng (ví dụ: hotfix đã được test kỹ).
Không dùng cho feature merge thông thường.
3-way merge: when merging 2 branches, git uses 3 snapshots:
1. Base (common ancestor): the commit where the 2 branches diverged
2. Ours (current branch HEAD)
3. Theirs (branch being merged in)
Git auto-resolves when: changes in the 2 branches do not touch the same region of code — git takes changes from both sides.
Conflict occurs when: both sides changed the same line, or one side deleted a file that the other side modified.
Conflict markers:
<<<<<<< HEAD
console.log("our change")
=======
console.log("their change")
>>>>>>> feature/loginManual resolve: remove the markers, keep the correct code, git add <file>, git merge --continue.
Merge strategies:
git merge -X ours feature/login # prefer our side on conflict
git merge -X theirs feature/login # prefer their side on conflict
# Use with caution — can silently lose codeWhen to use ours/theirs strategy: merging a release branch into main when you know one side is definitively correct (e.g., a heavily-tested hotfix).
Do not use for regular feature merges.