Practical Rollback Methods
Rollback Uncommitted Changes
Discarding Local Modifications
## Discard changes in a specific file
git checkout -- filename
## Discard all local changes
git checkout -- .
## Discard changes with force
git checkout -f
Managing Staged Changes
Unstaging Files
## Unstage a specific file
git reset HEAD filename
## Unstage all staged files
git reset HEAD
Commit-Level Rollback Strategies
Soft Reset
## Move HEAD back without changing working directory
git reset --soft HEAD~1
Hard Reset
## Completely remove commits and changes
git reset --hard HEAD~1
Reverting Committed Changes
## Create a new commit that undoes previous commit
git revert <commit-hash>
Rollback Workflow Visualization
graph TD
A[Local Changes] --> B{Committed?}
B -->|No| C[Discard Changes]
B -->|Yes| D[Choose Rollback Method]
D --> E[Soft Reset]
D --> F[Hard Reset]
D --> G[Revert Commit]
Advanced Rollback Techniques
Technique |
Use Case |
Complexity |
Soft Reset |
Preserving Changes |
Low |
Hard Reset |
Complete Removal |
Medium |
Revert |
Safe Public Rollback |
High |
LabEx Recommendation
Practice these rollback methods in a LabEx sandbox environment to build confidence and understanding without risking production code.