Mateo.

Git - Interactive Rebase

Open Interactive Rebase

git rebase -i HEAD~N      # rewrite last N commits
git rebase -i <hash>      # rewrite everything after this commit

An editor opens listing the commits. Change the command word on each line to control what happens.

Available Commands

CommandWhat it does
pickKeep commit as-is
rewordKeep commit, edit the message
editPause to amend the commit itself
squashMerge into previous commit, combine messages
fixupMerge into previous commit, discard this message
dropDelete the commit entirely

Squash Last N Commits into One

git rebase -i HEAD~3
# In editor: change 2nd and 3rd "pick" lines to "squash"
# Save → write the combined commit message
git push origin your-branch --force-with-lease

Reword a Commit Message

git rebase -i HEAD~3
# Change target line from "pick" to "reword"
# Save → a new editor opens for just that message

Drop a Commit

git rebase -i HEAD~5
# Change target line from "pick" to "drop" (or delete the line entirely)

Abort if Something Goes Wrong

git rebase --abort