How To Squash Your Last 2 Git Commits

Why Squash Commits?

If you’ve been working with Git for a while you might start to wonder why you can’t combine that last trivial “hello world” type commit with your previously more meaningful commit.

Fortunately, you don’t have to wonder as Git provides a nice way to do this.

Steps for Squashing Your Last 2 Git Commits

Let’s say your git log looks like this:

1
af81b37 - (HEAD feature_w) Fixed typo in feature name (2 minutes ago) 
2
da9ee9b - Added new feature W (11 minutes ago) 
3
g392876 - Added new feature Z (2 days ago) 

To squash the last 2 commits, at the command prompt type:

1
 git rebase -i HEAD~2 

This will open up your text editor with the following lines:

1
pick da9ee9b Added new feature W (11 minutes ago) 
2
pick af81b37 Fixed typo in feature name (2 minutes ago) 

Now you can tell Git what you want to do with each commit – pick, edit, or squash a commit.

Let’s change it to the following since fixing a typo is not really a worthwhile commit message.

1
pick da9ee9b Added new feature W (11 minutes ago) 
2
squash af81b37 Fixed typo in feature name (2 minutes ago) 

When you’re finished just save and Git will squash your commits.

Caution: Don’t squash commits that have already been shared with others via a public push/pull. It will mess up the history and cause you headaches.

Installing Phantomjs on Linux Mint 16

Just wrote a protip on Coderwall about how to install Phantomjs on Linux Mint 16

Setting Up Spring + RSpec For Testing Your Rails 4 Application

What is spring? Spring is an application preloader. That means it boots up your rails application and keeps it running in the background. Why is this good? It means you don’t have to boot it up every time you need to run a test

Continue Reading …

Avoiding the ‘oCol is undefined’ Error with jQuery-datatables-rails

The ‘oCol is undefined’ Error Recently I installed jQuery-datatables-rails in a Rails 4 project. With the Firebug plugin in Firefox, I received an error ‘oCol is undefined’. With Google Chrome via the console, I received an error ‘Cannot

Continue Reading …

Integrating Fat Free CRM Into Your Rails Application

What is Fat FREE CRM? Fat Free CRM is an open-source customer relationship management piece of software that lets you perform the basic marketing activities integral to the sales cycle. Tracking leads, managing campaigns, and contact lists are

Continue Reading …

How to Pass Javascript Functions Without Them Firing

In Javascript, functions are first-class citizens. Implications? This means you can pass functions around in Javascript like they were variables. Here’s some example code to illustrate the concept. //setup prototype function

Continue Reading …

Why You As a Client Want a Rails Codebase With Tests

Would you ever stop changing the oil on your car? I wouldn’t. It’s part of the maintenance that leads to a longer life span for my car and ensures it runs smoothly. In fact, because the automobile industry has done such a good job of educating

Continue Reading …

How to Move One Directory Into Another Directory With Linux and Git

Recently, I was tired and used the Linux mv command and erased a whole bunch of websites when I was SSHing into my web host account. So now I am going to document how to use the mv command just for kicks (and because it’s a short, fun thing to blog

Continue Reading …

Part 5 – Creating, Reading, Updating, and Deleting Tasks

From part 4 of the tutorial, we have set up our polymorphic associations. Now it's time to be able to give users the ability to CRUD (create, read, update, and delete) some tasks.

Continue Reading …

Fixing RSocialize: Where To Put the Custom Options in RSocialize?

I wrote a gem called RSocialize a while ago to help make it easier to install social media buttons on your Rails application.

Continue Reading …