Interactive rebase

Interactive rebase is rebase while tidying up the branch. It's mostly the "tidying up" component that people will use it for.

Imagine you make a large number of commits in a rush, may be under the deadline's pressure. You later find out:

  • Some commits are not critical and can be omitted

  • Some commits should be merged into one.

  • Some commits have bad commit messages.

  • etc.

Command

It's still rebase, but with the interative flag

git rebase -i
git rebase -interactive

What this will do is to

  • list all commits in the branch to be rebased, and

  • ask you what to do for each of them. E.g. whether to use the original commit, or modify it, or delete it.

Options include:

# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit

The default option is pick which means use the commit. If all commits are picked, the scenario reduces to a normal rebase. But you can choose to drop, edit or squash the commits, which normal rebase won't allow you to do.

Last updated