Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Concepts

git reset modes compared

Compare the git reset modes --soft, --mixed, --hard, --merge and --keep: which of HEAD, index and working tree each one changes, and how to undo a reset.

git reset <mode> <commit> moves the current branch to <commit> and then, depending on the mode, also rewrites the index and the working tree to match. The mode only decides how far the change travels through the three trees: HEAD, then the index, then the working tree.

If you omit the mode, --mixed is used. If you omit the commit, HEAD is used, which is why git reset alone just unstages everything.

Terminal
git reset --soft  HEAD~1   # move the branch only
git reset         HEAD~1   # --mixed: also reset the index
git reset --hard  HEAD~1   # also overwrite the working tree
git reset --keep  HEAD~1   # like --hard, but refuses to lose local edits

Try it

Bash What each mode leaves behind

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Recovering from a hard reset

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
git reset [--soft | --mixed | --hard | --merge | --keep] [<commit>]
git reset [<commit>] -- <paths>...
Mode HEAD / branch Index Working tree
--soft moved kept (so the undone changes stay staged) kept
--mixed (default) moved reset to <commit> kept (changes become unstaged)
--hard moved reset overwritten, local edits lost
--merge moved reset files that differ between index and HEAD are kept; others updated; aborts if an edit would be lost
--keep moved reset updates files changed between HEAD and <commit>; aborts if you have local edits in those files

With paths, git reset <commit> -- file does not move any branch; it only copies that file from <commit> into the index (the old way to unstage a file).

Usage notes

  • --soft is for redoing a commit. After git reset --soft HEAD~3, the changes of the last three commits are staged, ready to be committed as one.
  • --mixed is for splitting a commit or unstaging: changes remain on disk but nothing is staged.
  • --hard is the only mode that destroys uncommitted work. Staged and unstaged edits to tracked files are gone for good, not even the reflog has them. Untracked files survive.
  • Committed work is recoverable. ORIG_HEAD is set by reset, and git reflog lists earlier tips (see reflog).
  • Resetting a shared branch rewrites history. Never reset and force-push a branch others use; use git revert instead (see Undoing things).
  • --merge and --keep exist for cases such as abandoning a merge or moving a branch back while keeping unrelated local edits.
  • Resetting a branch you are not on is done with git branch -f name <commit>.