Git Cheat Sheet · Rewrite history
Interactive rebase
git rebase -i <commit>
git rebase -i <commit> opens the list of commits that follow this commit. For each one, you choose an action: keep it, rename it, edit it, squash it into the previous one or delete it. You can also change their order.
What it does
Reorganizes a series of commits: reorder, rename, squash, edit or delete.
A use case
Before opening your pull request, you group "wip" commits and correct the messages.
Warning: Rewrites history: avoid it on commits others have already fetched.
On the command line
git rebase -i HEAD~5- Reworks the last 5 commits.
pick- Keeps the commit as it is.
reword- Keeps the commit, but changes its message.
edit- Stops on the commit to change it (
git commit --amend, thengit rebase --continue). squash / fixup- Merges with the previous commit, combining the messages or keeping the previous one's.
drop- Deletes the commit.
In Merathon
- Right-click the oldest commit to touch up → "Interactive rebase of <branch> from this commit…".
- Choose an action per commit: Keep, Rename, Edit, Squash, Fixup or Delete.
- Drag the rows to change the order, then click "Start rebase".
- If the rebase stops (conflict or "Edit"), the right panel's banner offers "Continue".
Frequently asked questions
How do I undo an interactive rebase?
During the rebase, git rebase --abort. Afterwards, git reflog then git reset --hard <hash before>.
What is git commit --fixup?
git commit --fixup <commit> creates a correction commit; git rebase -i --autosquash places and merges it by itself.