Unstage the last local commit on git

This can be done using the git reset command to move the HEAD pointer back one commit while keeping the changes in your working directory.

git reset HEAD~1

The command has successfully unstaged your last commit. The changes from that commit are now back in your working directory, but they are not staged or committed. You can now:

  1. Review the changes
  2. Make additional modifications if needed
  3. Stage and commit the changes again when you’re ready

Revert the last local changes

This will discard all uncommitted changes in your working directory and staging area. Since this is a destructive operation, I’ll use git reset –hard to revert to the last commit.

git reset --hard HEAD

What Happens

  • All uncommitted changes are discarded
  • Working directory returns to the state of the last commit
  • Staging area is cleared
  • ⚠️ Warning: This operation cannot be undone