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.

https://gyazo.com/c08dce9412e75485247ad525dc4f0fb8

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:

https://gyazo.com/0837b44edb3f7b9988231c5be3c45eac

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

https://gyazo.com/8fd7d8f1f5a269123c84c8b436523572

Hmmm, let’s see what is it about:

https://gyazo.com/623f0a0140fa5aff5ad0c4241ee5c286

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

https://gyazo.com/2d557df4369cdfadc8bdd66f0d053722

Indeed. Ok, lemme:

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

https://gyazo.com/2b99b52a3d4d30be5c43ef4b1f7e51b5

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

Yes!

https://gyazo.com/b4a1d69e137e6f9afae6e3f1837474bb

Happy King’s Day!

The need to extend an npm package

The need to extend an npm package

Situation

So, I’ve written a simple Math library and distributed it as an npm package. For testing purposes, jasmine-node is used.

However, when it came to testing my logarithm functions, the supported methods didn’t totally fit my case. Specifically, I wanted to use to test that a log(0) equals to negative infinity. Having already used similar methods of the library, such as toBeNaN(), I was expecting that a similar method (i.e. toBeNegativeInfinity() ) would also exist.

Nonetheless, it didn’t and of course one could easily argue “why not working around it, like toEqual(-Infinity) ?”, but then, what is the point of having methods like toBeNaN()? We could also work around this with toBeEqual(NaN).

Solution

So, I decided to extend it a bit, because I didn’t want to wait  math.js already had a dependency on jasmine-node package, so, I had to provide my own (extended) version of jasmine-node. How could I do this?

  1. Fork jasmine-node
  2. Clone the forked repo locally
  3. Extend the library to my liking
  4. Distribute a new npm package out of the extended library (1)
  5. Replace jasmine-node dependency with jasmine-node-xt (2)
  6. Use the desired method as initially

Declarations

(0) : Following the concept of also extending the library I used, instead of just providing a PR and wait whether it will be accepted or not, I saved time from something that might never happen in the future from my side; on the other hand, I gained knowledge on an area I am not so experienced, so, even if the submitted PR is not gonna be accepted, I learned something new!
(1) : Required changes in package.json; here you also have to keep in mind the provided license from the original library – it might affect the way you wanna distribute your extended version of that library
(2) : First uninstall jasmine-node : npm uninstall –save-dev jasmine-node and then install our version: npm install –save-dev jasmine-node-xt