Move HEAD / reset index
high risk
git stash push -u -m "backup"Stash before a hard resetgit reset --soft HEAD~1Keeps your changesgit revert <commit>Safe for pushed commitsMoves the current branch to another commit; --soft keeps changes staged, --mixed unstages, --hard discards.
| Flag | Meaning |
|---|---|
--soft --soft | Keep changes staged |
--mixed --mixed | Keep changes unstaged (default) |
--hard --hard | Discard all changes⚠ Uncommitted work is lost permanently. |
git reset --soft HEAD~1Undo the last commit, keep changes · explain & risk-check →git reset HEAD fileUnstage a file · explain & risk-check →Reference text is hand-written and may be incomplete — check man git for your version. Test destructive commands on a non-production system first.