Intermediate · 7 min read
Interactive rebase without fear
Reorder, merge, rename or drop commits before sharing them.
Open the todo list
Git opens your editor with one line per commit, oldest first. Save and close to apply.
$ git rebase -i HEAD~4
The verbs
pick: keep. reword: change the message. edit: stop to modify the commit. squash: merge into the previous commit and combine messages. fixup: same, keeping the previous message. drop: delete. Moving lines reorders commits.
If something goes wrong
During the rebase, --abort puts everything back. After it, the reflog still has your old branch.
$ git rebase --abort$ git reflog -n 10
The golden rule
Only rewrite commits that nobody else has pulled. Then push with --force-with-lease.
$ git push --force-with-lease