Nâng CaoGit iconGit

Rebase interactive: edit mode cho phép làm gì mà squash không làm được?

edit trong interactive rebase dừng tại 1 commit cụ thể, cho phép bạn amend nó trước khi tiếp tục rebase.

Những gì edit làm được mà squash không:

1. Tách 1 commit thành nhiều commits:

bash
git rebase -i HEAD~3
# Đánh dấu commit cần tách là: edit abc123
# Git dừng tại abc123
git reset HEAD~  # unstage commit, giữ files
git add src/auth/
git commit -m "feat(auth): add login logic"
git add src/tests/
git commit -m "test(auth): add login tests"
git rebase --continue

**2.

Chèn commit mới vào giữa history:**

bash
# Dừng tại commit cần chèn trước
# Tạo file mới, commit
git add new-file.ts
git commit -m "feat: add missing helper"
git rebase --continue

**3.

Thay đổi nội dung file trong commit cũ (không chỉ message):**

bash
# Dừng tại commit cần sửa
# Edit files
git add changed-file.ts
git commit --amend --no-edit
git rebase --continue

Cẩn thận: edit mode tạo ra commits mới với hash khác → mọi commits phía sau cũng có hash mới → cần force push.

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

Mở danh sách Git