Skip to content

Reset

In one line

Reset moves the current branch pointer to a different commit, effectively rewinding history. The three modes control what happens to staged and working files.

In simple words

git reset moves the current branch pointer to a specified commit, rewinding history. It has three modes that control what happens to the staging area and working directory:

  • --soft: moves the branch pointer only; staged changes and working files are untouched. The undone commit's changes appear as staged.
  • --mixed (default): moves the pointer and unstages changes; working files are untouched. Changes appear as unstaged.
  • --hard: moves the pointer, unstages, AND discards all working directory changes. Everything is lost.

Reset rewrites history — the undone commits become unreachable. This is fine for local branches but dangerous for shared branches. Use git revert instead for shared branches.

Example

bash
# Undo last commit, keep changes staged
git reset --soft HEAD~1

# Undo last commit, unstage changes
git reset HEAD~1

# Undo last commit, discard ALL changes
git reset --hard HEAD~1

reset moves the branch pointer. --soft keeps staged, --mixed unstages, --hard discards all.

Common confusions

  • Confused with: revert

    The difference: reset rewinds the branch pointer (rewrites history); revert adds a new inverse commit (preserves history). Use reset locally, revert on shared branches.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary