git reset
Move the current branch pointer backward, discarding or unstaging commits
Practical example
git reset --soft HEAD~1 # undo commit, keep changes staged git reset --mixed HEAD~1 # undo commit, unstage (default) git reset --hard HEAD~1 # undo commit, discard everything
Command overview & how it works
Moves the current branch pointer to a previous commit, effectively undoing commits. The three modes control what happens to your working directory and staging area. git reset --soft HEAD~1 moves the branch pointer back but leaves all changes staged — useful for amending or squashing commits. git reset --mixed HEAD~1 (default) moves the pointer and unstages changes — files remain modified in your working directory. git reset --hard HEAD~1 moves the pointer, unstages, and discards all changes — files revert exactly to the target commit. Use git reset <file> to unstage a specific file without affecting other files. Never use --hard on commits you have not backed up, and never reset commits that have been pushed to a shared branch — use git revert instead.
Disaster-proof your Git workflow with the Field Guide
Learn how to rescue deleted branches, revive detached HEADs, and undo bad rebases without panic. 97-page PDF + ePub — ₹499.
Practical tips
- Use --soft to keep changes staged, --mixed (default) to unstage but keep the files, and --hard to discard everything.
- Never run git reset --hard on commits you have not backed up — check the reflog first if you are unsure.
- Use git reset <file> (without a commit) to simply unstage a file without touching history.
Deep-dive guides & tutorials
In-depth walkthroughs and practical scenarios related to git reset
- Tutorial
How to Undo Almost Anything in Git
From amending commits to recovering deleted branches — a practical guide to Git's safety net commands.
7 min readRead guide - Tutorial
Git Reflog: Recover Lost Commits and Branches
Deleted a branch? Lost commits after a reset? Git reflog tracks every movement of HEAD and can recover what seems lost forever.
5 min readRead guide - Tutorial
Git Stash: Save and Restore Work in Progress
Stop committing half-finished work. Learn how git stash temporarily shelves changes so you can switch contexts cleanly.
5 min readRead guide
Related commands
More from Undoing Changes