git reset
intermediateMove the branch pointer and undo your staging decisions.
git resetWhat it does
git reset rewinds your branch to an older commit. Depending on the mode it also resets the index (mixed), the index AND working tree (hard), or neither (soft). It's the power tool for 'I went too far' — and, unlike a delete, it never touches your reflog, so it can always be undone.
--soft/mixed/hard pick how far back the branch, index and worktree go
Watch it — press play
A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.
Step 1
Too far, too fast
A bad commit sits at the tip of your branch. You want the branch pointer to slide back over it.
git reset --hard HEAD~1The oops commit is on top
Under the hood
Reset moves the branch ref — not HEADs file
Reset takes the commit you're pointing at and rewrites refs/heads/<you> to an older hash. HEAD itself keeps pointing at the same branch file; the branch just moves backward.
git reset --soft HEAD~2 # branch now at old commit main: 9a2f1c0 ← 4b7c2a5 ← 74d3b9f(moved away)
The three modes are all about the index
Mixed (default) resets the branch AND the index. Soft moves only the branch (index stays staged). Hard moves branch, index AND rewrites the working tree. The mode picks which of the three stores (branch / index / worktree) gets rolled back.
The old commits aren't deleted
Nothing is removed from objects/. Unlinked commits simply become unreachable — and the reflog still lists them. `git reset --hard HEAD@{1}` brings you straight back.
Never reset shared history
Because reset rewinds the branch pointer, anyone who cloned that branch will see it vanish and require force-push reconciliation. Use git revert instead on shared branches.
Aliases the pros type
Memorize the git reset concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:
git config --global alias.st # → git resetg resgit resetMixed reset — unstage but keep files.
g resshgit reset --soft HEAD~1Undo the last commit, keep it staged.
g reshardgit reset --hard HEADDiscard ALL local uncommitted changes.
Command anatomy
--softMove the branch only; keep the index staged.
--mixedDefault: move branch + unstage the index; keep files.
--hardMove branch, wipe the index AND the working tree.
<path>Reset just that path in the index from another revision.
When to reach for it
You committed to the wrong branch: reset --soft to fix the pile and re-commit elsewhere.
Unstage everything: git reset (mixed) — the index-dance escape hatch.
Full revert of local-only mess: git reset --hard HEAD.
Pro tip
Training rule for the three modes: SOFT forgets the commit, MIXED also forgets the staging, HARD also forgets the files. Memorize as 'the deeper the reset, the more you lose' — and that reflog can always rebuild it within 90 days.