git cancel code example
Example 1: git discard local changes
# Discarding local changes (permanently) to a file:
git checkout -- <file>
# Discard all local changes to all files permanently:
git reset --hard
Example 2: revert local commit
$ git reset --hard HEAD~1
Example 3: undo last commit
git reset --soft HEAD~1
Example 4: how to undo a commit
$ git reset --soft HEAD~1