0
0
Gitdevops~3 mins

git reset soft vs mixed vs hard - When to Use Which

Choose your learning style9 modes available
The Big Idea

What if you could rewind your project like a video, choosing exactly what to keep or erase?

The Scenario

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.

The Problem

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.

The Solution

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.

Before vs After
Before
rm -rf changed_files
cp backup_files .
git commit -m 'fix mistakes'
After
git reset --soft HEAD~1
git reset --mixed HEAD~1
git reset --hard HEAD~1
What It Enables

You can easily rewind your project to a previous state, choosing exactly how much to keep or discard, making fixes fast and safe.

Real Life Example

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.

Key Takeaways

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.