Skip to main content
⚡ OpenDevDocs
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.
ModeMoves 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~1

2. Unstage All Files without Losing Changes (--mixed):

git reset HEAD

3. Completely Discard All Local Commits & Changes (--hard):

git reset --hard origin/main

On this page