Thursday, April 9, 2015

Ramblings from Git World - Squashing commits into a single commit for a PR



Often times when we are committing to our development branches off a private fork in github, it is a good idea to commit often so if something catastrophic were to happen, all the work is not lost. However, official github repository owners don't want to see all those commits clouding or sphagettizing (yes, pasta is the meal du jour at the household) the official upstream repository. It is a github best practice then to squash all your commits into a single upstream facing commit. Here are the steps to accomplish that:

Let's assume the upstream remote is labeled as official and the master branch on that remote is called master. Also, let's for the purpose of this excercise, assume that the feature development branch off your fork (fork off the official repository) is called dev_feature.

Once you've made all the commits locally that you need to and pushed it to your dev_feature branch off the origin (your fork of the official repository), and are ready to create a PR:

Run:

git log --oneline official/master..dev_feature

This should show all the commits you have made locally that are ready for a PR.

commit_hash1 First commit for dev_feature.
commit_hash2 Some more changes for dev_feature.
commit_hash3 Even some more changes for dev_feature.
....

Now our goal is squash all the commits into one so that when we merge the PR, the commit history is linear.

In order to do this run:

git rebase -i official/master

A new window will pop up showing all your commits like so:

pick commit_hash1 First commit for dev_feature
pick commit_hash2 Some more changes for dev_feature
pick commit_hash3 Even some more changes for dev_feature

# Rebase commit_hash1..commit_hash3 onto commit_hash1
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
# ...

Do pick on the first commit and say squash on all others. Save the changes and exit. This will pop a new window and allow you to enter a new commit message. 

# This is a combination of 3 commits.
# The first commit's message is:

First commit for dev_feature

# This is the 2nd commit message:

Some more changes for dev_feature

# This is the 3rd commit message:
Even some more changes for dev_feature

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# ...

Once this is done, if you run;

git log --oneline official/master..dev_feature

it should only show a single commit like so:

new_commit_hash

The only thing left then is to push your changes to the remote dev_feature branch on the remote origin (i.e. your fork off the official). In order to do that do:

git push --force --set-upstream origin dev_feature.

Once the origin fork has your changes, just create the PR, get code review comments, and after builds and regression passes, merge your PR.

Note the same steps hold true even if you've already created the PR off the dev_branch and are squashing your commits just prior to merging the PR upstream. Also, it is a good idea to periodically also push your local commits to the upstream fork on the origin using:

git push --set-upstream origin dev_feature.

The --force flag is required only when you are rewriting the commit history on the dev_feature branch on the remote origin.

That should do it for tonight! :)

Sifar.


p.s. Credit where credit is due.

Sunday, July 24, 2011

New Beginnings

In my previous posts, I have made it amply clear that I am confused when it comes to how mere reflections of the ONE can walk varied paths towards realizing the ONE true Self. I have been at conflict as to how deep within the human DNA is carved the need to find a life partner and procreate when the real yearning beyond all these is to reach the state of salvation, to realize the ONE. Great wise men have through times talked about these conflicts and have provided answers in their own ways to reach salvation or nirvana - via Karma, via Bhakti, via Knowledge. The great Swami Vivekananda has advised the less enlightened mortals to practice all of the above in their life-time to reach the ONE. He mentions that people should enjoy all the worldly pleasures in their life and when their yearnings for these worldly pleasures are satisfied, they would hunger for more, look for answers, for a purpose to their life, and therein they would turn back to basics of Bhakti, of Knowledge and of Karma.

In line with this thought, and in an attempt to find answers to the conflicts within ME, I have been currently reading Practical Vedanta by Swami Ranganathananda. The book elaborates what Vivekananda told us in his lectures on Hinduism. It has been a great read so far and explains the four Purusharthas in life viz. dharma, karma, kama, and moksha. The reason I started off on such a spiritual note is to drive home this point about the four Purusharthas. I was re-introduced to these Purusharthas again, when I got married back in June of this year. The priest explained to me and my lovely wife R that marriage is all about living these four Purusharthas. As per the priests' advice, we hope to follow dharma, enjoy kama, work the karma, and attain the moksha. While R and my journey has just begun, we are hoping to find answers to the conflicting questions, answers to realize through marital bliss, the spiritual enlightenment, we all seek.

-- Sifar (The Full Circle)

Wednesday, February 2, 2011

Content With Maiden Content Management System

Got done creating my first Drupal7 powered CMS site for the company intranet and hosting it on an Ubuntu VM. A few quirks and sys-ad sorta things and the site is fully operational within a span of less than a week with all bells n whistles such as admin notifications and rules and cron jobs and the jazz...

I started off developing a test site using MAMP on OSX and Drupal7.0 and then migrated it to the VM server running Lucid Lynx and LAMP + Webmin. MySQL was the DB of choice with a mix of PhpMyAdmin and sqladmin to do the DB craziness.


Configuration and a list of modules that worked:

Ubuntu Lucid Lynx + Drupal7.0 + LAMP (configured via webmin)

Had to use the Rules module instead of User Registration Notification Module which c^#%^$d out.
Had to use the SMTP Authentication Support Module cuz Sendmail/PostFix sucked.


Just content with the overall effort though!

-- Sifar

Saturday, January 22, 2011

I, MMXI

MMXI and I Are In Harmony.

Read a lovely blog post by Antonio Cangiano.

+1 to my RSS feeds.

All in all an enjoyable evening hacking and reading tech-posts.

Nothing much to talk about otherwise, cuz my work is giving me a lisp.

Ohh btw, Content Farm? I like ContentVille Better, FB $uck yeah!

Cheers,
Sifar.

Thursday, December 16, 2010

Heal your VPN client (Mac)

Today the Cisco VPN client on the Mac cra##%d out on me right in the middle of a VPN connection. When I tried to reconnect it kept on failing with the error:

“A configuration error occurred. Verify your settings”

Several retries later, I was positive it wasn't the VPN server itself that was the problem.

Although I had to leave the error at that for the time-being, come evening when I got back home, I stumbled upon this link. Bottom line, if you ever see this error on OSX, you may want to try to restart the racoon service using something to the effect of:

sudo service com.apple.racoon stop
sudo service com.apple.racoon start

Note that the OSX recommends you to use launchctl instead of service, so that would mean you do this:

sudo launchctl stop com.apple.racoon
sudo launchctl start com.apple.racoon

That did the trick for me. Hope it does for you.

-- Sifar