Skip to main content

Reset

It is used to undo changes by moving the HEAD (current branch pointer) to a different commit. It allows you to remove commits, unstage changes, or discard modifications in the working directory.

Types

Reset ModeDescription
--softMoves the branch pointer to a previous commit but keeps changes staged.
--mixedMoves the branch pointer to a previous commit and unstages changes but keeps them in the working directory.
--hardMoves the branch pointer to a previous commit and discards all changes.

Commands

  • git reset <commit> – Moves the branch to a specific commit (default: mixed reset).
  • git reset --soft <commit> – Moves the branch to a commit, keeping changes staged.
  • git reset --mixed <commit> – Moves the branch to a commit, unstaging changes (default behavior).
  • git reset --hard <commit> – Moves the branch to a commit and deletes all changes.
  • git reset HEAD <file> – Unstages a file without changing its content.
  • git reset --hard HEAD – Discards all uncommitted changes.
  • git reset --keep <commit> – Like --hard but preserves uncommitted changes that do not conflict.
  • git reset --merge – Aborts a failed merge, similar to git merge --abort.

Comparison

Featuregit resetgit revert
HistoryRemoves commitsCreates a new commit to undo changes
SafetyCan be destructive (--hard)Safe for shared branches
Use CaseUndo commits locallyUndo commits in a public branch