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 viewRebase hell happens when: branch has lived too long, conflicts appear in many commits, you resolve wrong then continue → next conflict is even more complex.
Strategy:
1. Abort and squash first:
bash
git rebase --abort
# Squash branch into 1-2 commits
git rebase -i origin/main # squash all → fixup
# Then rebase again — only need to resolve once**2.
Incremental rebasing:**
bash
# Instead of rebasing onto current main (50 commits ahead),
# rebase onto a midpoint commit first
git rebase abc123 # commit from 3 weeks ago
# Resolve conflicts
git rebase origin/main # from there to current**3.
Use rerere (Reuse Recorded Resolution):**
bash
git config --global rerere.enabled true
# Git remembers how you resolved a conflict → auto-replays next time**4.
When stuck — inspect each step:**
bash
git status # see which files are conflicted
git diff # see diff before resolving
git rebase --skip # skip this commit (only when it becomes empty after conflict resolution)
git rebase --abort # return to pre-rebase state**5.
Use a merge tool:**
bash
git mergetool # open vimdiff / VSCode / IntelliJ merge view