Interactive rebase (git rebase -i) cho phép edit lịch sử commit local trước khi share.
Workflow chuẩn trước merge PR:
bash
git rebase -i HEAD~5 # edit 5 commits gần nhất
# hoặc
git rebase -i origin/main # tất cả commits chưa mergeTrong editor hiện ra:
pick abc123 feat: add user model
pick def456 fix typo
pick ghi789 wip: half done
pick jkl012 fix tests
pick mno345 final cleanupThay đổi:
- squash (s): merge commit này vào trước, giữ message
- fixup (f): merge vào trước, BỎ message (dùng cho "fix typo", "wip")
- reword (r): giữ commit, chỉ edit message
- drop (d): xóa commit hoàn toàn
- edit (e): dừng lại tại commit để amend
Ví dụ kết quả tốt: 5 WIP commits → 1 clean commit feat(auth): implement JWT login with refresh tokens
Lưu ý quan trọng: CHỈ rebase commits chưa push lên remote (hoặc trên branch riêng của bạn). Rebase shared commits = disaster cho teammates.