Git
gitgitGuideIntermediate
git reset — Undoing Commits Locally
Mastering git reset: soft vs mixed vs hard resets, moving HEAD pointers, rescuing lost commits via reflog, and dangerous pitfalls.
Verified: 2026-09-30
Platforms:
all
#git#reset#undo#danger
git reset — Undoing Commits Locally
The git reset command moves the current branch HEAD pointer backward to a specified commit. It is used to undo local commits, unstage files, or completely wipe local changes.
1. Comparing the Three Reset Modes
┌─────────────────────────┐
│ git reset <commit> │
└────────────┬────────────┘
│
┌───────────────────────────┼───────────────────────────┐
▼ ▼ ▼
[ --soft ] [ --mixed ] [ --hard ]
Moves HEAD pointer only. Moves HEAD + unstages. Moves HEAD + wipes staging
Preserves staged index Keeps changes on disk + PERMANENTLY DESTROYS
and working disk files. in working directory. uncommitted disk changes.| Mode | Moves HEAD? | Updates Staging Area (Index)? | Modifies Working Tree (Disk)? | Risk Level |
|---|---|---|---|---|
--soft | ✅ Yes | ❌ No (Preserved) | ❌ No (Preserved) | Safe |
--mixed (default) | ✅ Yes | ✅ Yes (Unstages) | ❌ No (Preserved) | Safe |
--hard | ✅ Yes | ✅ Yes (Wiped) | ⚠️ Yes (WIPED) | Dangerous |
2. Practical Examples
1. Undo Last Commit but Keep All Code Staged (--soft):
git reset --soft HEAD~12. Unstage All Files without Losing Changes (--mixed):
git reset HEAD3. Completely Discard All Local Commits & Changes (--hard):
git reset --hard origin/mainRelated Topics
git stash — Temporarily Shelving Changes
How to stash uncommitted changes: git stash save, git stash pop, stashing untracked files (-u), viewing stash lists, and dropping stashes.
git revert — Safe Public History Reversal
How to safely undo commits on shared public branches: creating inverse inverse-diff commits, revert vs reset differences, and reverting merge commits.