git reset
command
Moves HEAD and optionally the index/working directory to a previous state.
Syntax
git reset [--soft | --mixed | --hard] <commit>
Example
bash
# Unstage a file (safe)
git reset HEAD file.php
# Keep changes, undo commit
git reset --soft HEAD~1
# Undo commit and unstage (default)
git reset --mixed HEAD~1
# Undo commit AND discard changes (DESTRUCTIVE)
git reset --hard HEAD~1
--hard discards uncommitted changes permanently. Use with caution.