Adding a Change to an Old Commit

In this episode, we will fix an old commit by enhancing it with a new, separate commit.

Transcript
Adding a Change to an Old Commit

In this episode, we will fix an old commit by enhancing it with a new, separate commit.

There are many use cases for this workflow. Most likely, we forgot to add a change or we simply made a mistake in an old commit.

The beauty of the workflow we’re going to use is its simplicity: we can simply create a new commit with the changes we would have wanted in that original commit. And we’ll see in a minute how we can add those changes to that old commit using a feature called “fixup”.

So let’s look at our example scenario. And let’s say we forgot to add some changes to this “Change headlines” commit here. We’ve already prepared these missing changes, so we’re ready to go.

In Tower, we can just stage these changes and commit them. There’s absolutely nothing to watch out for in this step - just a normal commit with any message you like.

Now let’s work the magic: we can now select both commits - the original one and that new band aid commit - then right-click one of them and select “Fixup” from the menu.

Fixup works almost exactly like the squash feature (in that it combines two commits). But the difference is that it only keeps the commit message of the oldest commit (because it considers the newer commits as fixups).

When we confirm this, we’ll notice two things: first, this ugly fixup commit has been removed from the history. And second, the changes contained in this fixup commit have now been added to our original commit. Just like we wanted!

Well… that’s already it! Squash and fixup are really simple to use in Tower. And we now have a clean commit history again.