Python Git Reset: Deep Dive into --soft, --mixed & --hard
git reset moves the active branch pointer (HEAD) backward to a specified target commit. The 3 reset modes control what happens to the Staging Area and Working Directory: --soft preserves both index and working tree; --mixed (default) resets the index but preserves working tree; --hard erases changes from both.
"Imagine your project is a document: --soft is like moving the bookmark back but keeping all typed text highlighted on screen ready to commit; --mixed un-highlights the text into your draft; --hard throws your paper draft into the paper shredder."
Deep Dive: How It Works
git reset --soft HEAD~1: Un-commits the last commit, leaving all files staged in the index ready to re-commit.
git reset --mixed HEAD~1: Un-commits and un-stages the files, keeping changes in working directory.
git reset --hard HEAD~1: Completely overwrites index and working tree to match target commit. Destructive!
Syntax Blueprint
git reset --soft HEAD~1 # Keep staged git reset --mixed HEAD~1 # Keep in working dir (default) git reset --hard HEAD~1 # Discard completely
Select exact reset mode based on whether you wish to keep staged changes, unstaged changes, or wipe them.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Running git reset --hard when you had uncommitted edits you wanted to keep.Why it happens: Misunderstanding that --hard discards unstaged files without warning.
How to fix: Always stash (git stash) before running reset --hard.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Perform Soft Reset
Perform a soft reset to the previous commit using "git reset --soft HEAD~1".
Verify staged status with "git status --short".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.