how to un commit git code example

Example 1: how to uncommit my last commit in git

git reset --soft HEAD^

git reset HEAD^
//And if you actually want to completely undo it, throwing away all uncommitted changes, resetting everything to the previous commit (as the original question asked):

git reset --hard HEAD^

Example 2: undo local commit

$ git reset --soft HEAD~1

Example 3: revert last commit

git reset HEAD~

Example 4: undo last commit

$ git reset --hard HEAD~1

Example 5: git undo last commit

git reset --soft HEAD~1

Example 6: git undo last commit

$ git reset --soft HEAD~1