Monday, March 19, 2012

Git'ing Around

I was dusting off some of the ol' Sinatra skills today, and thought I'd start by browsing through the source of a project by one of the better Ruby coders out there - it's really the best way to learn. But alas, the project I had used to the same effect over a year ago had migrated to Rails!!!

Thankfully, the awesomeness of Git and Github came to the rescue - I simply forked the project, looked back through the commit log, found the commit that introduced Rails, then "re-mastered" my fork so that commit was the new HEAD. And how did i do all that?

1. Fork the project on Github.

2. git clone$USERNAME/$REPO.git

3. git log
- find relevant commit, note down first 8 chars of the commit SHA. Lets say that was '12345678'

4. git reset --hard 12345678

5. git push origin master -f

That's it - you've now effectively taken the forked repo back in time.