git rebase
INTERACTIVE MODE
Rebasing interactively means that you have a
chance to edit the commits which are rebased. You
can reorder the commits, and you can remove them.
Start it with the last commit you want to
retain as-is:
git rebase -i <after-this-commit>
An editor will be fired up with all the commits in
your current branch (ignoring merge commits),
which come after the given commit.
By replacing the command “pick” with the command
”edit”, you can tell git rebase to stop after
applying that commit, so that you can edit the
files and/or the commit message, amend the commit,
and continue rebasing.
If you just want to edit the commit message for a
commit, replace the command “pick” with the
command “reword”.
To drop a commit, replace the command “pick” with
”drop”, or just delete the matching line.
If you want to fold two or more commits into one,
replace the command “pick” for the second and
subsequent commits with “squash” or “fixup”.
When you are done editing and/or resolving
conflicts you can continue with
git rebase --continue
.
For example, if you want to reorder the last 5
commits, such that what was HEAD~4 becomes the
new HEAD. To achieve that, you would call git
rebase like this:
$ git rebase -i HEAD~5