</>
⌕
Mid #rebase#squash#fixup#history

Interactive rebase để squash và dọn lịch sử commit

⚡ Trả lời nhanh

git rebase -i <base> mở danh sách commit để pick, reword, squash, fixup, drop hoặc đổi thứ tự, viết lại lịch sử thành các commit gọn. Chỉ nên dùng trên nhánh chưa chia sẻ vì commit sinh ra có hash mới.

git rebase -i HEAD~4
pick   a1b2c3 feat: add cart
squash d4e5f6 fix typo          # gộp vào commit trên, giữ message
fixup  789abc wip               # gộp vào commit trên, bỏ message
reword 0fedcb add tests         # đổi message
git commit --fixup a1b2c3                  # tạo commit fixup gắn với a1b2c3
git rebase -i --autosquash origin/main     # tự sắp xếp fixup
git rebase --abort                         # huỷ nếu rối
LệnhTác dụng
squashgộp, cho sửa message gộp
fixupgộp, bỏ message
dropxoá commit
🃏 Ôn bằng flashcard