Worst case conflict: không phải thêm/xóa dòng đơn giản mà là structural refactor — function bị rename, logic được reorganize.
Quy trình an toàn:
1. Hiểu context trước khi resolve:
git log --oneline main..feature/my-branch # xem commits của feature
git log --oneline feature/my-branch..main # xem commits của main
git diff $(git merge-base HEAD feature/my-branch) feature/my-branch -- src/file.ts
# Xem feature branch đã thay đổi gì**2.
Dùng 3-panel merge tool (không resolve bằng tay trong terminal):**
git mergetool # opens configured tool
# Left: ours, Right: theirs, Center: base (common ancestor)
# Bottom: result**3.
Resolve và verify:**
git add src/file.ts
# CHƯA commit — chạy tests trước:
npm test -- --testPathPattern=file.ts
# Nếu pass:
git merge --continue**4.
Sau merge — review lại result:**
git diff main~1..main -- src/file.ts # xem diff của merge commitNguyên tắc: khi không chắc, chọn solution bảo toàn logic của cả 2 sides thay vì chọn 1 side.
Đừng dùng -X ours hay -X theirs với structural conflicts.
Worst case conflict: not a simple add/delete but a structural refactor — a function was renamed, logic was reorganized.
Safe process:
1. Understand context before resolving:
git log --oneline main..feature/my-branch # commits in feature
git log --oneline feature/my-branch..main # commits in main
git diff $(git merge-base HEAD feature/my-branch) feature/my-branch -- src/file.ts
# See what the feature branch changed**2.
Use a 3-panel merge tool (do not resolve manually in the terminal):**
git mergetool # opens configured tool
# Left: ours, Right: theirs, Center: base (common ancestor)
# Bottom: result**3.
Resolve and verify:**
git add src/file.ts
# Do NOT commit yet — run tests first:
npm test -- --testPathPattern=file.ts
# If passing:
git merge --continue**4.
After merge — review the result:**
git diff main~1..main -- src/file.ts # view the merge commit diffPrinciple: when in doubt, choose a solution that preserves the logic of both sides rather than picking one side.
Never use -X ours or -X theirs for structural conflicts.