Nâng CaoGit iconGit

Đang rebase gặp conflict phức tạp ở nhiều commits. Chiến lược xử lý mà không bị "rebase hell"?

Rebase hell xảy ra khi: branch sống lâu, conflict ở nhiều commits, resolve sai rồi continue → conflict tiếp theo phức tạp hơn.

Chiến lược:

1. Abort và squash trước:

bash
git rebase --abort
# Squash branch thành 1-2 commits
git rebase -i origin/main  # squash all → fixup
# Sau đó rebase lại — chỉ cần resolve 1 lần

**2.

Rebase từng bước nhỏ:**

bash
# Thay vì rebase lên main hiện tại (50 commits ahead),
# rebase lên commit ở giữa trước
git rebase abc123  # commit từ 3 tuần trước
# Resolve conflicts
git rebase origin/main  # từ đó lên hiện tại

**3.

Dùng rerere (Reuse Recorded Resolution):**

bash
git config --global rerere.enabled true
# Git ghi nhớ cách bạn resolve conflict → tự replay lần sau

**4.

Khi bị stuck — inspect từng bước:**

bash
git status          # xem files nào conflict
git diff            # xem diff trước khi resolve
git rebase --skip   # bỏ qua commit này (chỉ khi commit thực sự empty sau conflict)
git rebase --abort  # về trạng thái trước rebase

**5.

Dùng merge tool:**

bash
git mergetool  # mở vimdiff / VSCode / IntelliJ merge view

Xem toàn bộ Git cùng filter theo level & chủ đề con.

Mở danh sách Git