Beautify your git history by rebasing

1. Introduction

percircle is a project I started on 2015, without having a clue about js (which is still valid :-P), but of course, there’s always place for improvement.

Today I noticed that I was creating a dirty history with several small unnecessary commits, so, I thought about experimenting a bit.

2. Situation

Below you can see a not-so-nice history of 4 commits. What they actually are about is 2 commits for the readme file and a corresponding release to npm for each one of them. But those two changes could be displayed as one, since only the latest is the one that contains the proper changes. So, I wanna somehow erase commits f13df6d and 12632de.

3. Solution

For this, I will be needing the help of git rebase. Specifically, I wanna rebase on top of the latest release, prior to any changes in the readme file. That is, the commit for November 3:

git rebase -i e1a7e698d399b51cfd2cf283e0ff25d8aa23175c

I then just “drop” the commits that I don’t wanna be included in my history anymore and totally be deleted:

I save the file and I see that there’s an issue:

Hmmm, let’s see what is it about:

Ok, let’s go heck what is wrong with this version (I suspect it has to do with versioning):

Indeed. Ok, lemme:

  • keep the proper version
  • resolve the conflict
  • continue rebasing and
  • force the push

The most important part of such a rebase is to eventually force the push, so that a rewrite occurs in the history’s tree.

4. Result


Happy King’s Day!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s