Interactive rebase 는 commit editor
git rebase -i <base> 가 <base> 와 현재 HEAD 사이 모든 commit 을 한 줄씩 보여주는 editor 를 열어. 줄을 편집해 Git 에 지시: 이 commit 유지, 저거 drop, 둘 reorder, 이거 squash, 저거 message edit, 여기 멈추고 amend 시켜줘. 저장 + 종료하면 Git 이 스크립트대로 commit 을 replay. 결과: 같은 (또는 편집했으면 다른) 내용에 도달하는 다른 모양의 history.
각 줄 앞 동사가 지시. pick 은 commit 그대로. reword 는 변경 유지 + 메시지 rewrite. edit 는 그 commit 에서 rebase 멈추고 임의 변경으로 git commit --amend 가능, 그 다음 git rebase --continue. squash 는 이전 commit 에 fold + 메시지 결합. fixup 은 squash 인데 fixup commit 메시지 폐기. drop 은 commit 완전 삭제. 줄 재배열 = commit 재배열, 줄 삭제 = drop.
가장 유용한 패턴: git rebase -i main 으로 merge 전 feature branch 정리 — WIP 수정을 parent commit 에 squash, 실험적 우회 drop, 모호한 메시지 reword. Commit 10 개를 3 logical unit 으로 재구성. 몇 달 된 commit 의 지금 부끄러운 log 줄 제거: git rebase -i <hash>~1, target 을 edit 으로, 고치고, git rebase --continue.
안전 사실 둘. Rebase 는 history rewrite. Commit hash 가 바뀜. 그 commit 이 push 됐고 남이 썼으면 조율 문제. Rebase 는 reversible. Push 전엔 git reset --hard ORIG_HEAD 가 rebase 전으로 rewind. Push 후에도 reflog 가 pre-rebase tip 을 90일 보유. Interactive rebase 중 실수는 loud (Git 이 conflict 에 멈춤) + recoverable (reflog) — 더 안전한 'powerful' Git 연산 중 하나.