Skip to main content
Back to command reference
Undoing Changes

git reset

Move the current branch pointer backward, discarding or unstaging commits

Practical example

bash
git reset --soft HEAD~1          # undo commit, keep changes staged
git reset --mixed HEAD~1        # undo commit, unstage (default)
git reset --hard HEAD~1         # undo commit, discard everything

Command overview & how it works

Moves the current branch pointer to a previous commit, effectively undoing commits. The three modes control what happens to your working directory and staging area. git reset --soft HEAD~1 moves the branch pointer back but leaves all changes staged — useful for amending or squashing commits. git reset --mixed HEAD~1 (default) moves the pointer and unstages changes — files remain modified in your working directory. git reset --hard HEAD~1 moves the pointer, unstages, and discards all changes — files revert exactly to the target commit. Use git reset <file> to unstage a specific file without affecting other files. Never use --hard on commits you have not backed up, and never reset commits that have been pushed to a shared branch — use git revert instead.

Chapter 07 · Disaster Recovery Drills

Disaster-proof your Git workflow with the Field Guide

Learn how to rescue deleted branches, revive detached HEADs, and undo bad rebases without panic. 97-page PDF + ePub — ₹499.

Learn more

Practical tips

  • Use --soft to keep changes staged, --mixed (default) to unstage but keep the files, and --hard to discard everything.
  • Never run git reset --hard on commits you have not backed up — check the reflog first if you are unsure.
  • Use git reset <file> (without a commit) to simply unstage a file without touching history.

Deep-dive guides & tutorials

In-depth walkthroughs and practical scenarios related to git reset

All guides →

Related commands

More from Undoing Changes