Just like almost every morning, today I got up and got setup to continue working on a client’s website only to find that after doing my first $git pull of the day in order to update my local setup, I had pulled an uncompleted commit somebody else in my team had pushed a few days ago.

So, what do you do when you need to go back to your previous commit (thankfully, I had already committed my changes locally)? Here are a couple of things you could do:

– Revert working copy to most recent commit, ignoring any changes:

git reset --hard HEAD

– Or, reverting working copy to an older commit:

Reset index to former commit. Replace ‘XXXXX’ with your commit code

git reset XXXXX

Moves pointer back to previous HEAD

git reset --soft HEAD@{1}
git commit -m "Revert to XXXXX"

Updates working copy to reflect the new commit
git reset --hard

Happy repo!