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 =-)