Bird
Raised Fist0
Gitdevops~5 mins

git reset soft vs mixed vs hard - CLI Comparison

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Sometimes you want to undo changes in your project. Git reset helps you move back to an earlier state. It has three ways to do this: soft, mixed, and hard. Each one changes your files and history differently.
When you want to undo a commit but keep your changes to fix or edit them before committing again.
When you want to undo a commit and unstage the changes but keep them in your files to work on.
When you want to completely undo a commit and remove all changes from your files and staging area.
When you accidentally committed too early and want to adjust your last commit without losing work.
When you want to discard all recent changes and return your project to a clean state.
Commands
This moves the last commit out of the history but keeps all your changes staged, so you can edit or recommit easily.
Terminal
git reset --soft HEAD~1
Expected OutputExpected
No output (command runs silently)
--soft - Moves HEAD to the previous commit but keeps changes staged.
This moves the last commit out of history and unstages the changes, but your files still have the changes to edit or review.
Terminal
git reset --mixed HEAD~1
Expected OutputExpected
No output (command runs silently)
--mixed - Moves HEAD and unstages changes but keeps them in files.
This moves the last commit out of history and removes all changes from both staging and files, making your project exactly like the previous commit.
Terminal
git reset --hard HEAD~1
Expected OutputExpected
HEAD is now at <commit-hash> <commit-message>
--hard - Moves HEAD and discards all changes in staging and files.
Check the current state of your files and staging area after reset to see what changed.
Terminal
git status
Expected OutputExpected
On branch main Your branch is behind 'origin/main' by 1 commit and can be fast-forwarded. nothing to commit, working tree clean
Key Concept

If you remember nothing else, remember: soft reset keeps changes staged, mixed reset unstages changes but keeps them in files, and hard reset removes all changes completely.

Common Mistakes
Using git reset --hard without realizing it deletes all unstaged changes.
This causes loss of work because changes in files and staging are removed permanently.
Use git reset --soft or --mixed if you want to keep your changes for editing.
Confusing --soft and --mixed and expecting changes to be unstaged after --soft reset.
Soft reset keeps changes staged, so they appear ready to commit, which can confuse users expecting them unstaged.
Use --mixed if you want changes unstaged but still in files.
Running git reset without specifying a mode and expecting it to keep changes staged.
By default, git reset uses --mixed, which unstages changes, so staged changes are lost.
Always specify --soft if you want to keep changes staged.
Summary
git reset --soft moves HEAD back but keeps changes staged for easy recommit.
git reset --mixed moves HEAD back and unstages changes but keeps them in files.
git reset --hard moves HEAD back and removes all changes from staging and files.

Practice

(1/5)
1. What does git reset --soft do to your changes after undoing a commit?
easy
A. It unstages the changes but keeps them in the folder.
B. It removes the changes from both staging and folder.
C. It keeps the changes staged and ready to commit again.
D. It deletes the commit and all changes permanently.

Solution

  1. Step 1: Understand git reset --soft effect

    This option moves the HEAD pointer back but keeps all changes staged.
  2. Step 2: Compare with other reset types

    Unlike mixed or hard, soft reset does not unstage or delete changes.
  3. Final Answer:

    It keeps the changes staged and ready to commit again. -> Option C
  4. Quick Check:

    soft reset = keep staged changes [OK]
Hint: Soft reset keeps changes staged for quick recommit [OK]
Common Mistakes:
  • Confusing soft with mixed reset
  • Thinking soft deletes changes
  • Assuming soft unstages changes
2. Which of the following is the correct syntax to undo the last commit but keep changes unstaged?
easy
A. git reset --keep HEAD~1
B. git reset --soft HEAD~1
C. git reset --hard HEAD~1
D. git reset --mixed HEAD~1

Solution

  1. Step 1: Identify the reset option for unstaging changes

    The --mixed option resets the commit and unstages changes but keeps them in the folder.
  2. Step 2: Verify syntax correctness

    All commands use HEAD~1 to move one commit back; --mixed is the default and correct option here.
  3. Final Answer:

    git reset --mixed HEAD~1 -> Option D
  4. Quick Check:

    mixed reset = unstage but keep changes [OK]
Hint: Mixed reset unstages but keeps changes in folder [OK]
Common Mistakes:
  • Using --soft when unstaging is needed
  • Using --hard which deletes changes
  • Using invalid --keep option
3. Given you committed changes but want to undo the commit and remove all changes from your working folder, what will be the result of git reset --hard HEAD~1?
medium
A. The commit is undone, changes remain staged.
B. The commit is undone, changes are deleted from folder and staging.
C. The commit is undone, changes remain unstaged in folder.
D. The commit is undone, changes are saved in stash.

Solution

  1. Step 1: Understand --hard reset effect

    This option resets the commit and deletes all changes from both staging and working folder.
  2. Step 2: Confirm no changes remain

    After hard reset, the working folder matches the commit pointed by HEAD, so changes are lost.
  3. Final Answer:

    The commit is undone, changes are deleted from folder and staging. -> Option B
  4. Quick Check:

    hard reset = delete changes from folder and staging [OK]
Hint: Hard reset deletes changes from folder and staging [OK]
Common Mistakes:
  • Thinking hard reset keeps changes staged
  • Confusing hard with mixed reset
  • Assuming changes are saved in stash automatically
4. You ran git reset --soft HEAD~1 but your changes disappeared from staging. What is the likely cause?
medium
A. You ran git reset --mixed instead of soft.
B. You committed new changes after reset.
C. Your Git version does not support --soft option.
D. You actually ran git reset --hard by mistake.

Solution

  1. Step 1: Analyze why changes are unstaged

    Soft reset keeps changes staged; if changes disappeared from staging, mixed reset was likely used.
  2. Step 2: Check command confusion

    Mixed reset unstages changes but keeps them in folder, matching the symptom.
  3. Final Answer:

    You ran git reset --mixed instead of soft. -> Option A
  4. Quick Check:

    Mixed reset unstages changes, soft keeps staged [OK]
Hint: Unstaged changes? Check if mixed reset was used instead of soft [OK]
Common Mistakes:
  • Confusing soft and mixed reset effects
  • Assuming Git version lacks --soft support
  • Thinking reset deletes changes automatically
5. You committed changes but realize you want to undo the commit, keep the changes unstaged, and then selectively stage some files. Which command sequence achieves this?
hard
A. git reset --mixed HEAD~1; git add <files>
B. git reset --soft HEAD~1; git add <files>
C. git reset --hard HEAD~1; git add <files>
D. git reset --soft HEAD~1; git reset HEAD <files>

Solution

  1. Step 1: Undo commit and unstage changes

    git reset --mixed HEAD~1 moves HEAD back, unstages changes but keeps them in folder.
  2. Step 2: Selectively stage files

    Use git add <files> to stage only desired files after unstaging.
  3. Final Answer:

    git reset --mixed HEAD~1; git add <files> -> Option A
  4. Quick Check:

    Mixed reset + selective add stages chosen files [OK]
Hint: Use mixed reset to unstage, then add files selectively [OK]
Common Mistakes:
  • Using soft reset which keeps all changes staged
  • Using hard reset which deletes changes
  • Trying to unstage files after soft reset