What if you could rewind your project like a video, choosing exactly what to keep or erase?
git reset soft vs mixed vs hard - When to Use Which
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you made several changes to your project files and committed them, but then realized you need to undo some or all of those changes. You try to fix this by manually deleting files, copying old versions, or redoing commits by hand.
This manual undo process is slow and risky. You might delete important work by mistake, lose track of what was changed, or create confusion in your project history. It's easy to get stuck or make things worse.
Using git reset with its soft, mixed, and hard options lets you undo commits safely and quickly. Each option controls how much of your work is kept or removed, so you can fix mistakes without losing important changes.
rm -rf changed_files
cp backup_files .
git commit -m 'fix mistakes'git reset --soft HEAD~1 git reset --mixed HEAD~1 git reset --hard HEAD~1
You can easily rewind your project to a previous state, choosing exactly how much to keep or discard, making fixes fast and safe.
A developer accidentally commits unfinished work. Using git reset --soft, they undo the commit but keep changes staged to fix and recommit quickly without losing progress.
Soft reset undoes commits but keeps changes staged.
Mixed reset undoes commits and unstages changes but keeps them in files.
Hard reset undoes commits and discards all changes completely.
Practice
git reset --soft do to your changes after undoing a commit?Solution
Step 1: Understand
This option moves the HEAD pointer back but keeps all changes staged.git reset --softeffectStep 2: Compare with other reset types
Unlike mixed or hard, soft reset does not unstage or delete changes.Final Answer:
It keeps the changes staged and ready to commit again. -> Option CQuick Check:
soft reset = keep staged changes [OK]
- Confusing soft with mixed reset
- Thinking soft deletes changes
- Assuming soft unstages changes
Solution
Step 1: Identify the reset option for unstaging changes
The--mixedoption resets the commit and unstages changes but keeps them in the folder.Step 2: Verify syntax correctness
All commands useHEAD~1to move one commit back;--mixedis the default and correct option here.Final Answer:
git reset --mixed HEAD~1 -> Option DQuick Check:
mixed reset = unstage but keep changes [OK]
- Using --soft when unstaging is needed
- Using --hard which deletes changes
- Using invalid --keep option
git reset --hard HEAD~1?Solution
Step 1: Understand
This option resets the commit and deletes all changes from both staging and working folder.--hardreset effectStep 2: Confirm no changes remain
After hard reset, the working folder matches the commit pointed by HEAD, so changes are lost.Final Answer:
The commit is undone, changes are deleted from folder and staging. -> Option BQuick Check:
hard reset = delete changes from folder and staging [OK]
- Thinking hard reset keeps changes staged
- Confusing hard with mixed reset
- Assuming changes are saved in stash automatically
git reset --soft HEAD~1 but your changes disappeared from staging. What is the likely cause?Solution
Step 1: Analyze why changes are unstaged
Soft reset keeps changes staged; if changes disappeared from staging, mixed reset was likely used.Step 2: Check command confusion
Mixed reset unstages changes but keeps them in folder, matching the symptom.Final Answer:
You rangit reset --mixedinstead of soft. -> Option AQuick Check:
Mixed reset unstages changes, soft keeps staged [OK]
- Confusing soft and mixed reset effects
- Assuming Git version lacks --soft support
- Thinking reset deletes changes automatically
Solution
Step 1: Undo commit and unstage changes
git reset --mixed HEAD~1moves HEAD back, unstages changes but keeps them in folder.Step 2: Selectively stage files
Usegit add <files>to stage only desired files after unstaging.Final Answer:
git reset --mixed HEAD~1; git add <files> -> Option AQuick Check:
Mixed reset + selective add stages chosen files [OK]
- Using soft reset which keeps all changes staged
- Using hard reset which deletes changes
- Trying to unstage files after soft reset
