Skip to main content
Undoing Changes

git reset

Move the current branch pointer backward, discarding or unstaging commits

Practical Example

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.

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.

Related Commands in Undoing Changes