Overview
This module covers how to rewrite Git history safely and recover from mistakes using reset, revert, rebase, reflog, and advanced recovery techniques.
Learning Objectives
- Understand the difference between reset and revert
- Use
git resetsafely (soft, mixed, hard) - Use
git revertto undo commits safely - Understand
git rebaseand when to avoid it - Recover deleted branches and lost commits
- Rescue work from detached HEAD
- Build a repeatable recovery checklist
Topics Covered
Part 1: Rewriting History
7.1 Why History Changes Matter
- Shared history vs local history
7.2 git reset (Soft, Mixed, Hard)
- What each mode changes
7.3 git revert
- Safe undo for shared branches
7.4 git rebase (Conceptual)
- Replaying commits
7.5 Interactive Rebase (Conceptual)
- Squash, reword, drop
7.6 Fixing the Last Commit
- amend vs reset
7.7 Undoing a Merge Commit
- Revert merge
7.8 Recovering with Reflog
- Finding lost commits
7.9 Safe History Rules
- Never rewrite shared history
7.10 History Cleanup Best Practices
- Clean, readable history
Part 2: Advanced Undo & Recovery
7.11 Undo vs Recovery
- When to undo vs when to recover
7.12 Cherry-Pick Recovery
- Reapply commits safely
7.13 Reflog Deep Dive
- Find lost work
7.14 Recovering a Deleted Branch
- Restore from reflog
7.15 Revert a Revert
- Undo the undo
7.16 Reset Safety Checklist
- Before you reset
7.17 Restore Specific Paths
- File-level undo
7.18 Recovering Stash Mistakes (Advanced)
- Stash commits and reflog
7.19 Rescue Detached HEAD Work
- Save work before it disappears
7.20 Recovery Best Practices
- Calm, repeatable steps
Hands-on Exercises
- Use
git reset --softand--mixed. - Revert a commit on a shared branch.
- Perform an interactive rebase (conceptual).
- Recover a lost commit using reflog.
- Recover a deleted branch using reflog.
- Revert a bad commit, then revert the revert.
- Rescue a detached HEAD commit.
Key Takeaways
- Reset rewrites history; revert preserves it.
- Rebase cleans history but should stay local.
- Reflog is your ultimate safety net.
- Recovery is a process, not a guess.
Additional Resources
- Pro Git: Reset, Revert, and Undoing Things
git help reset,git help revert,git help reflog
Next Module
Module 08 will cover Tags, Releases & Release Management.