Undo most recent commit both locally and remotely

September 13, 2022

When to use reset:

git reset --hard HEAD^
git push -f
  • the reset command changes the commit history and it might overwrite history that remote team members depend on
  • use the reset command if the commit being reset only exists locally

When to use revert:

git revert <COMMIT>
git push
  • the revert command creates a new commit that undoes the changes
  • use the revert command if the commit being reset has been pushed to the remote