Git Reset Cheat Sheet

Git reset — soft, mixed, and hard reset explained. Undo commits, manipulate staging area, and understand the danger levels of each mode.

Last Updated: May 1, 2025

Reset Modes

ModeHEADIndex (Staging)Working DirectorySafe?
--softMovesUnchangedUnchangedVery safe — changes stay staged
--mixed (default)MovesReset to HEADUnchangedSafe — changes become unstaged
--hardMovesReset to HEADReset to HEADDangerous — all changes lost!
--mergeMovesResets merged filesKeeps unmergedSafer than --hard
--keepMovesUnchangedReset files with changesAborts if local changes exist

Practical Reset Commands

git reset HEAD~1
Mixed: undo last commit, keep changes unstaged
git reset --soft HEAD~1
Soft: undo last commit, keep changes staged
git reset --hard HEAD~1
Hard: undo last commit AND discard all changes
git reset HEAD file
Unstage a specific file (keep changes)
git reset -- file
Alternative: unstage file (keep changes)
git reset --soft origin/main
Undo all local commits, keep work staged
git reset --hard origin/main
Reset to remote state — discard ALL local work
git reset --soft HEAD~3 && git commit
Squash last 3 commits into one

When to Use Each Mode

ItemDescription
--softUndo commits but keep all changes staged — ready to re-commit
--mixedUndo commits, put changes back in working tree for re-staging
--hardNuclear option — complete reset to a known state. Reflog is your backup
HEAD~NReset back N commits; combine with mode flags
File-Level Resetgit reset file or git restore --staged file to unstage
Remote ResetReset local to match remote: git fetch && git reset --hard origin/main
Squash WorkflowReset --soft followed by a new commit = manual squash
Recover After Resetgit reflog → find lost commit → git reset --hard HEAD@{n}

Reset vs Other Commands

ItemDescription
reset vs revertReset removes history; revert creates new undo commit (safer for shared branches)
reset vs restoregit restore discards working changes; reset moves HEAD
reset vs checkoutcheckout switches branches; reset --hard with a file discards its changes
reset vs cleangit clean removes untracked files; reset works on tracked files
--merge vs --hard--merge is safer — it won't delete unmerged changes
Pro Tip: Think twice before `git reset --hard`. There's no undo except reflog. Prefer `--soft` or `--mixed` when you might need the changes back.