Git — Reset
Reset Types
| Type | Command | Description |
|---|---|---|
| Soft | git reset --soft | Keep changes staged |
| Mixed | git reset | Keep changes unstaged |
| Hard | git reset --hard | Discard all changes |
Soft Reset
# Undo last commit, keep changes staged
git reset --soft HEAD~1
Mixed Reset (Default)
# Undo last commit, keep changes unstaged
git reset HEAD~1
Hard Reset
# Undo last commit, discard all changes
git reset --hard HEAD~1
Reset to Specific Commit
git reset --hard commit-hash
Unstage Files
# Unstage all
git reset HEAD
# Unstage specific file
git reset HEAD file.txt
Dangerous Operations
# Discard all changes
git reset --hard HEAD
# Discard everything including untracked
git clean -fd
Mini Practice
- Soft reset last commit
- Mixed reset changes
- Hard reset to discard
- Unstage files
Up Next
Continue with Revert — reverting commits.
Related Topics
Frequently Asked Questions about Reset
What is Reset in Git?
Reset is a fundamental concept in Git. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Reset?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Reset.
Why is Reset important in Git?
Reset is essential for Git development. Understanding this concept will help you write better code and solve real-world problems more effectively.