Coding/Learn/git/git reset soft mixed hard
Git & GitHub Complete Course
01.Introduction, Architecture & Configuration
02.Staging Area, atomic Commits & git status
03.Branching, Fast-Forward & 3-Way Merging
04.Stash, Log Visualization & History Inspection
05.Workflows (Git Flow, Trunk-Based) & Semantic Tagging
06.SSH Keys, Remote Repositories & Origin Setup
07.Push, Fetch, Pull & Upstream Tracking Branches
08.Forking, Clones & Open-Source Pull Requests (PRs)
09.GitHub Flow, Branch Protection & GitHub Pages
10.Undoing Changes: git restore & Safe Public git revert
11.Reset: Deep Dive into --soft, --mixed & --hard
12.Commit Amending & Interactive Rebase (git rebase -i)
13.Reflog & Disaster Recovery (Reviving "Lost" Commits)
14.Merge Conflicts Resolution & git rerere
15..gitignore Rules & .gitattributes Cross-Platform Handling
16.Hooks & Automated Quality Assurance (Pre-Commit)
17.Submodules & Large File Storage (Git LFS)
18.GPG Cryptographic Signing & git cherry-pick
19.Advanced Remotes, Garbage Collection (git gc) & Maintenance
20.Capstone: Production Multi-Branch Enterprise Release Pipeline
Course Certificate0%

Complete all lessons to earn

LearnGit Reset: Deep Dive into --soft, --mixed & --hard
11 / 20 0%
Lesson 11 of 20
6 mins read

Git Reset: Deep Dive into --soft, --mixed & --hard

PreviousNext Lesson
In Plain English

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.

The Mental Model

"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.

PointCore Rules to Remember

Point star
--soft for Re-packaging: Ideal when you committed too early and want to add more staged files into the commit.
Point star
--mixed Default: Safely undoes commits while keeping every line of your code intact on disk.
Point star
--hard Danger: Uncommitted working directory changes cannot be recovered by Git if overwritten by --hard.

Common Beginner Traps & How to Fix Them

Mistake: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.

Pro Tip: Use git reset --soft HEAD~1 to squash your last 3 local micro-commits into one clean commit before opening a PR.

Live Interactive Example

Hit Run Code to see it live
Soft Reset for Commit Restructuring
Git 2.45 / CLI
1
2
3
4
5
6
7
8
9
10
11
Output Console
Click "Run Code" to view the rendered output.
How it works: Status "M " indicates app.c remains staged in the index ready for an updated commit message.

Your Turn: Micro Challenge

No pressure! Edit the starter code below and test your solution with instant feedback.

Micro Exercise

Perform Soft Reset

  • PointPerform a soft reset to the previous commit using "git reset --soft HEAD~1".
  • PointVerify staged status with "git status --short".
1
2
3
4
5
6
7
8
9
10
11
Sandbox Output
Click "Run & Check" to test your solution.

Finished reading and practicing?

Mark this lesson as completed to update your course progress.

PreviousNext Lesson
Overview100 SheetLearnCertificates