This is a cheat sheet for undoing changes in git.
vim example.txt
Undo with:
git checkout -- example.txt # fetch file from repository
git stash [save <description> # save for later
git reset --hard # reset whole repository
git add example.txt
Undo with:
git reset HEAD example.txt
git commit
Undo with:
git revert HEAD # with revert commit
git commit --amend # redo last commit with next commit
git reset HEAD^ --hard # remove last commit
git push
Undo with:
git revert HEAD ; git push # revert in new commit
git reset HEAD^ --hard && git push origin -f # remove commit and force push