====== Delete Last Commit in GIT ======
Once in a while late at night when I'm sleepy, I'll commit stuff to my repository that I wish I hadn't. Then I spend the next 10 to 15 minutes searching the Internet how to remove the last commit I made. So after a few times, I decided to record how to do it here so that I refer to it later.
Keep in mind that one you push your repository, you cannot delete the revision... To delete the last commit,
git reset --soft HEAD~1
HEAD~1 is a shorthand for the commit before head. Alternatively you can refer to the SHA-1 of the hash you want to reset to. Note that when using --soft any changes to tracked files in the working tree since the commit before head are still stored in the working copy. If you want to wipe out the work you have done, you can use --hard option that will delete both the commit and all of your changed files "Changes to be committed", as git status would put it.
If you have already pushed and someone pulled which is usually not my case, you can't use GIT reset. Instead, you'll need to do a GIT revert,
git revert HEAD
This will create a new commit that reverses everything introduced by the accidental commit.