Wednesday, December 11, 2013

The Git command every "junior" dev needs to save their butt.

Unless your perfect and never accidentally hit the wrong key when you don't mean to than keep reading.

Most Github articles walk you through some good basic commands others are WAY too advanced and in depth for beginners.  This command is the one to know when you have messed up. After knowing this command, you will have the absolute confidence and ability to not freak out when you do make a mistake.

I was doing front end work last week and made the mistake of getting caught up emotionally in an email from one of my bosses to check on a different site I had just made...BLAH..BLAH..BLAH long story short I ended up making some tweaks to the site that I was emailed about and quickly committed the changes as a "dumb-trying-to-impress-his-boss-noob" developer does.

Now here is where the story actually gets good. 3 Months ago I would have been freaking out and cursing myself under my breath for not being more careful and "measuring twice before cutting once".

However now after committing the coding atrocity I simply typed in 1 command and life was good once again and no one was the wiser to the fact that I had violated every good and healthy safety code check that should be done before committing your work. The magic Git command?

All I typed in was:            'git reset HEAD~1'

That's it! That command is your: "Get out of jail, I messed up with Git command"!

The best part is, its a totally safe command that doesn't erase your work or do anything that you don't want to happen. You are simply resetting the last commit, it doesn't erase anything it simply resets everything to how it was before the commit. You can reset the last commit many other ways, but for me this was a really easy one to remember that hopefully I WON'T need anytime soon  =-)

Please share in the comments what I did wrong, I know I was an idiot but being able to fix my mistake and not having to ask for help from the other developers, like the first month at work. I  realized that other young developers might want to keep it handy as well =-)


  1. This is very much appreciated. I have not had to unravel anything to such a degree since I am only working on my own dinky rails project at the moment but I will keep this in mind. Also if you come anymore of these n00b tips, please share. These info really helps really helps.

  2. Thanks Brian, I will keep on sharing if you keep on reading :-)

  3. How to undo the last Git Commit - has been my reference for long; I go looking for it once every 2-3 months :-)

  4. @Prakash Thanks for the comment and link!

  5. Hey Joshua - this article should help too :)

    p.s. I've been following your blog since I saw the Hacker News post. I seriously went from the very first post when you started to learn Ruby and read all of them in a row. Keep up that drive!

  6. OH. while I'm here, I was wondering whether you'd like to be interviewed for a blog post for Thinkful - an online programming school. My contact info is if you're interested :)

  7. @Bhaumik Sorry just saw this :-( ....would love to!!

  8. Compared with the glass reactor with jacket, the high quality stone crusher has wide applications. Here: Generally speaking, the stone crusher machine may include vibrating feeder, stone jaw crusher, pex jaw crusher, vertical shaft impact crusher, vibrating screen, sand washing machine etc.