Git Tutorial EclipseCon France 2014 - Git Exercise 06 - interactive rebase
1. Interactive Rebase
In this exercise you learn how you can rewrite the local history before you share it with
others. After you have committed locally you can still change all commits in your local
feature branch. You will use the interactive rebase feature which helps you combining
different actions in one operation.
Preparation
Follow exercise “Merging, Rebasing and Conflict Resolution”. After the rebase you end up
with a branch which is two commits ahead of the remote branch origin/master.
Add two additional commits
● In the feature branch, add a commit with a change you do not need and with another
commit which should in fact be part of the commit “Add multiply operation”
● Now you realize that you also want to edit the commit message of the commit “Add
divide operation”
Interactive Rebase
Interactive Rebase is a very powerful operation which allows to rewrite the history of a
branch. You can select a set of commits and specify for each one how it should be handled.
You can edit the commit message, edit the commit, skip the commit, change the order of
commits or squash commits together. We will try out some of the options in this exercise.
2. ● Click “Rebase interactive” on the parent of the first commit you want to change in
order to start interactive rebase:
● Now open the “Git Interactive Rebase” View
The commits are presented in the order they will be processed by interactive rebase.
Change the action for each of the commits like shown here:
● Click on the “Start” button
The list of actions is processed from top to bottom.
● The first commit has the action REWORD. EGit opens a dialog where you can edit
the commit message. Press OK. The commit is replaced by a new one which has the
new commit message.
3. ● The next commit is just picked. That means, that EGit cherry-picks this commit as
a successor of the first reworded commit which contains the same changes as the
picked commit.
● The next commit is skipped (removed on the branch rewritten by interactive rebase).
● The list of actions is updated during the Interactive Rebase:
● The last commit should be squashed with its predecessor commit. That means that a
new commit is created which replaces the predecessor and combines the changes of
both old commits. You can edit the commit message of the new commit in a dialog.
Note that the action FIXUP would also have combined the two commits but would
have silently taken the commit message of the first commit.