Interactive Rebase

Interactive Rebase allows you to manipulate your old commit history in almost any way.

Transcript
Interactive Rebase

In this episode, we will talk about a very powerful feature, the “Swiss Army Knife” of Git tools: Interactive Rebase. Very versatile, very powerful, but also very complicated to use from the Command Line.

Let’s take a look at how Interactive Rebase is integrated in Tower.

Interactive Rebase allows you to manipulate your old commit history. In our first scenario, we want to edit a commit message of an old commit. We can simply right-click the commit and select “Edit Commit Message” from the context menu. We can then edit the commit message in any way we want and click Save. That’s it - we have successfully manipulated an old commit.

Another thing you can do using Interactive Rebase is to delete a commit. To do this, right-click a commit and select “Delete”. This takes the commit out of the commit history and deletes it. Of course, this can result in merge conflicts as you are creating a new version of the Git history. Merge conflicts are a part of the game when it comes to manipulating Git history.

Next, let’s look at squashing commits, which means combining multiple commits into one. In this example, we have decided that the changes we committed are too granular and we want to combine two of these commits. All we need to do is to select those commits and choose “Squash”. We can also use drag & drop: simply drag one of the commits onto the other. This will combine the two commits - both their changesets and their commit messages.

And finally, let’s move on to editing or splitting commits. This feature basically allows you to re-open an old commit for editing. Let’s say we want to edit this commit here. Simply right-click the commit and choose Edit from the menu. This will bring the changeset back to the Working Copy, allowing us to edit it in any way we want. In this case, let’s say we committed this chunk by mistake, so let’s just discard that.

We also decided that we should have made two commits instead of one. So first, we’ll stage these changes and commit. Then, make a second commit with the remaining changes. That’s it, we’ve just modified the old commit and split it into two separate commits.

Before we wrap up this episode, a word of warning: please only use Interactive Rebase to manipulate old history if you haven’t pushed it yet. Only use it to clean up your local history before sharing it with your colleagues.