Git
Version Control
git reset
Software Development
Programming

What's the difference between git reset --mixed, --soft, and --hard?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

git reset --soft, --mixed, and --hard all move HEAD, but they differ in what happens to the index and working tree. The easiest way to choose correctly is to think in three layers: commit history, staging area, and files on disk. Once that model is clear, reset behavior becomes predictable.

Three-Layer Model

Git state can be viewed as:

  • 'HEAD pointer to current commit'
  • index or staging area
  • working tree files

Every reset mode moves HEAD. The chosen flag controls whether the index and working tree are also changed.

--soft: Keep Staging and Files

git reset --soft <target> moves HEAD only. Staged and unstaged changes remain as they were.

bash
# Undo latest commit but keep changes staged
git reset --soft HEAD~1
git status

Typical use cases:

  • rewrite commit message
  • squash local commits
  • split history later while preserving staging context

Because staging is preserved, you can recommit immediately with updated metadata.

--mixed: Unstage But Keep Files

git reset --mixed <target> moves HEAD and resets the index to target commit. Working tree files remain changed.

bash
# Default reset mode when flag is omitted
git reset HEAD~1
git status

Typical use cases:

  • unstage everything for selective restaging
  • split one commit into multiple focused commits
bash
1git add src/parser.c
2git commit -m "Fix parser edge case"
3
4git add tests/parser_test.c
5git commit -m "Add parser regression tests"

This is usually the safest cleanup mode for local history editing.

--hard: Reset Everything to Target

git reset --hard <target> moves HEAD, resets index, and rewrites working tree files to match target commit.

bash
# Discards local staged and unstaged edits
git reset --hard HEAD~1

Typical use cases:

  • intentionally discard local work
  • force local branch to exactly match another ref
bash
git fetch origin
git reset --hard origin/main

This is destructive for uncommitted changes.

Safety Practices Before Reset

Before any reset, check current state and recent history.

bash
git status
git log --oneline -n 5

If uncertain, create a recovery point:

bash
git branch backup/pre-reset-2026-03-04

Or stash first:

bash
git stash push -m "before reset"

These safeguards avoid avoidable data loss during history edits.

Local Versus Shared Branches

git reset rewrites local branch history. If commits were already pushed, reset plus force push can disrupt collaborators.

On shared branches, prefer git revert for safe undo semantics. If history rewrite is necessary, coordinate and use:

bash
git push --force-with-lease

This reduces accidental overwrite risk compared with plain force push.

Practical Decision Guide

Use this quick rule:

  • choose --soft when you want to keep staging unchanged
  • choose --mixed when you want file edits but cleared staging
  • choose --hard only when discarding local edits is intentional

Documenting this in team onboarding material prevents many accidental destructive resets.

If you are teaching new contributors, run all three modes on a disposable practice repository first. Seeing index and working-tree differences in git status after each reset builds intuition faster than memorizing definitions.

Common Pitfalls

  • Using --hard when only unstaging was intended.
  • Forgetting that git reset defaults to --mixed.
  • Rewriting already-pushed history without team coordination.
  • Skipping git status before destructive commands.
  • Assuming discarded local edits are always recoverable.

Summary

  • All reset modes move HEAD.
  • '--soft keeps index and working tree untouched.'
  • '--mixed resets index while preserving file changes.'
  • '--hard resets index and files to target commit.'
  • Choose mode based on exactly what local state you want to preserve.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.