Thursday, October 11, 2012

When your git branch diverges from your remote

This is a tricky state and in past when I occasionally got myself into it I could never cleanly recover from it. Until now. I just found a clean way.

What's this tricky problem?

You know that git commit --amend is a very useful way to make changes to your last commit. You can add a couple of diffs to it or just change the commit message. It works great as long as you haven't pushed that commit to any remote. If the remote already has your last commit and now you make changes to it locally, your local branch and the remote branch are going to diverge. You will get a message like this

# On branch master
# Your branch and 'origin/master' have diverged,
# and have 1 and 1 different commit(s) each, respectively.

If you try to push to remote, git won't let you (if I recall correctly). Therefore I almost always check whether I've pushed the commits to origin/master before I try to invoke --amend. But sometimes accidentally I forget to check and end up in this tight situation. Well today I got a way to resolve it.

The state of your git repository is like this

Remote: A --> B
         \
Local:  A --> C

After commit A, you created commit B and pushed it to the remote. Then you accidentally did --amend on commit B and changed it to commit C. Here are the steps to recover.
  1. Rewind C. In the past I described different ways of undoing a commit. One of them helps us here. We run git reset --soft HEAD^ to rewind commit C. That is, the changes in commit C come back to the staged state. Now these changes are sum of the diffs that went in commit B and the changes you added with --amend. 
  2. Note the changes you did in --amend (copy them somewhere, hopefully they weren't many). 
  3. Now either erase these changes with git checkout or stash them away with git stash save
  4. Now do a git pull. This will bring your local repo in sync with remote. i.e. your repo's HEAD will now be at commit B. 
  5. Now do the changes that you were trying to commit with --amend (that you saved somewhere earlier). 
  6. Now commit them as a new separate commit D. 
  7. If you had stashed the old mixed changes, do a git stash clear to loose them.
That's it. Now your local and remote branches will look like this after you push

Remote: A --> B --> D
         
Local:  A --> B --> D


Thursday, October 04, 2012

Something like Olivia - John Mayer

One of the best lyrics in John Mayer's latest album - "Born and Raised".

You find a deeper meaning when you ask why he says "Something" and not "Someone".



(and yes, I would like to believe he means Olivia Wilde :)

Monday, July 30, 2012

Kelsey Grammer is spectacular

After watching 11 seasons of Frasier, I couldn't imagine Kelsey Grammer could be anyone but a comedian. When I watched Boss I was glad to be wrong. The character of Tom Kane is as diametrically opposite of Frasier as possible and Kelsey has packed it with genuine terror of the scale I have rarely seen.

Monday, June 18, 2012

Why Patriotism doesn't make sense

Imagine you are one in a group of young students who are going on a field trip across the country in a plane. This is first time on a plane for most of you and everyone is eager to get the window seat to see how the world looks from high up in the sky. As the seating arrangement in a typical plane goes, some seats are in the middle which obviously can't offer the beautiful view that the window seats can. The teacher is going to make seat assignments and her decision is perfectly arbitrary. It is clear to everyone that, if you get the window seat you will get a magnificent view and if you get to sit in the middle row all you will see is the back of the seat before you.

Being unconditionally proud of the country of your birth means getting the seat in the middle row and claiming that it has the most spectacular view that anyone in the entire plane has.

Which country you are born in is as arbitrary as an unbiased teacher allocating seats on the plane. In that case, if you are born in a country that is not good at something, but you decide to stand up for it just because you were born there then you are fooling no one but yourself.

One should glorify or villify one's country based upon the logical/ethical/moral reasoning and not because one was born or not born in that country.



Here are some great quotes on the subject:

Patriotism is your conviction that this country is superior to all other countries because you were born in itGeorge Bernard Shaw

A nation is a society united by a delusion about its ancestry and by common hatred of its neighbours - William Ralph Inge

It is not easy to see how the more extreme forms of nationalism can long survive when men have seen the Earth in its true perspective as a single small globe against the stars - Arthur C Clarke

Can anything be stupider than that a man has the right to kill me because he lives on the other side of a river and his ruler has a quarrel with mine, though I have not quarrelled with him? - Blaise Pascal

Sunday, June 10, 2012

Prometheus

Prometheus in IMAX 3D was a great experience. Some of the scenes were mind blowing. Only regret is there weren't more of them.

The IMAX 3D experience is worth for some initial scenes - ones right after the opening titles - the sprawling and calm lake, roaring waterfalls of murky water. The most breath taking scene is watching the Prometheus ship hung in the middle of space and some time later watching it in the backdrop of the planet and its rings. I would like to watch it again and again. Too bad it only lasts 5-10 seconds in the movie. Also the scenes where the humans and human-made objects are shown besides the gigantic alien structures are also awe-inspiring.

These things are worth a trip to the theatre. But besides that, the story is lame. Characters and actors are good, but their motives and actions could have used more thought. A work of fiction is more appealing if it can be easily extrapolated from the reality we know.