How to Undo a Git Commit?

Committed but found issues, want to undo the last one or more commits

Solutions

Undo commit, keep changes in staging area Recommended

git reset --soft HEAD~1

HEAD,. Suitable for when you committed but want to modify and recommit.

Use case: want to modify commit content or message, changes are still needed

, ()

git reset HEAD~1

and more --mixed.,. New.

: New

and

git reset --hard HEAD~1

and, ( reflog).

:

git commit --amend -m "New "

,.

:,

git revert HEAD

New.,.

:,

--hard,
revert reset
reset, force push

Related Commands