Terminal GuideTerminal Guide

git reset Command Guide

Reset current HEAD to the specified state

8 min readLast updated: January 19, 2026
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Modes

git reset --soft HEAD~1Undo commit, keep staged
git reset HEAD~1Undo commit, unstage
git reset --hard HEAD~1Undo commit, discard all

Unstage

git reset HEAD <file>Unstage file
git resetUnstage all

Recovery

git reflogView history
git reset --hard HEAD@{1}Undo reset

Downloadable Image Preview

Failed to generate preview

Basic Usage

The git reset command moves the HEAD pointer and optionally modifies the staging area and working directory. It's used to unstage files, undo commits, or discard changes.

bash
# Unstage all files
git reset

# Unstage specific file
git reset HEAD file.js

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

Reset Modes

The three modes determine what happens to your changes:

ModeHEADStagingWorking Dir
--softMovedUnchangedUnchanged
--mixed (default)MovedResetUnchanged
--hardMovedResetReset
bash
# --soft: Undo commit, keep changes staged
git reset --soft HEAD~1
# Ready to commit again with different message

# --mixed (default): Undo commit, unstage changes
git reset HEAD~1
# Changes are in working directory, not staged

# --hard: Undo commit, discard all changes
git reset --hard HEAD~1
# Everything is gone - be careful!
Warning
--hard permanently discards uncommitted changes. There is no undo for changes that were never committed.

Unstaging Files

bash
# Unstage a file (keep changes in working directory)
git reset HEAD file.js

# Unstage all files
git reset

# Modern alternative (Git 2.23+)
git restore --staged file.js

Undoing Commits

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

# Undo last 3 commits
git reset --soft HEAD~3

# Undo to specific commit
git reset --soft abc1234

# Undo commit but keep changes to edit
git reset HEAD~1
# ... make edits ...
git add .
git commit -m "New message"

Recovery with Reflog

Git keeps a log of where HEAD has been, allowing recovery from mistakes:

bash
# View reflog
git reflog
# abc1234 HEAD@{0}: reset: moving to HEAD~1
# def5678 HEAD@{1}: commit: Add feature

# Recover from accidental reset
git reset --hard HEAD@{1}

# Or use the commit hash directly
git reset --hard def5678

Practical Examples

bash
# Oops, wrong commit message
git reset --soft HEAD~1
git commit -m "Correct message"

# Split a commit into two
git reset HEAD~1
git add file1.js
git commit -m "First change"
git add file2.js
git commit -m "Second change"

# Undo merge (not pushed)
git reset --hard HEAD~1

# Completely start over to match remote
git reset --hard origin/main

# Remove a file from staging
git reset HEAD secrets.json

Frequently Asked Questions

What is the difference between --soft, --mixed, and --hard?

--soft keeps changes staged. --mixed (default) unstages changes but keeps them in working directory. --hard discards everything - use with caution!

How do I undo a reset?

Use "git reflog" to find the commit hash before the reset, then "git reset --hard <hash>" to return to that state. This works as long as the commits haven't been garbage collected.

What is the difference between reset and revert?

Reset rewrites history by removing commits. Revert creates a new commit that undoes changes. Use revert for shared branches (safer), reset for local work.

How do I unstage a file without reset?

You can use "git restore --staged <file>" (Git 2.23+) which is clearer. It does the same thing as "git reset HEAD <file>".

Is it safe to use git reset --hard?

It permanently discards uncommitted changes. Only use it when you're sure you don't need those changes. Committed work can usually be recovered via reflog.

Summary

git reset is powerful for undoing changes locally. Use --soft to redo commits, --hard with caution.

Quick Reference

  • git reset --soft HEAD~1 - Undo commit, keep staged
  • git reset HEAD~1 - Undo commit, unstage
  • git reset --hard HEAD~1 - Undo commit, discard all
  • git reset HEAD <file> - Unstage file

Official Documentation

For authoritative information, refer to the official documentation:

Related Articles