Git - Undo of Things

After using Git for a while, you will run into situation when you have to revert changes you commited or even pushed to remote repository. This is what Version Control is good at, getting you back to previous state with least effort. Here are some very useful git commands to undoing things.

Removing Last Commit [Local]

git reset --soft HEAD~1
git reset --soft HEAD~2
git reset --soft <Last Good SHA Hash>

Undo Public Change (Remote)

git revert <SHA Hash>

This will create new commit to revert changes to the commit. This method is safe and most used method because it doesn’t delete the commit history.

Undo to Particular Commit Hash

git revert --no-commit <<commitHash>>..HEAD
git commit

Undo Commit Merge

git revert -m 1 [sha_of_C8]