Reflog & Recovery
๐ Covered in this chapter:
HEAD ยท git reflog ยท Recovering Deleted Branches ยท Dangling Commits
Recover seemingly lost commits and branches using git reflog โ Git's local, personal safety net.
1Reflog & Recovery โ What You'll Learn
Recover seemingly lost commits and branches using git reflog โ Git's local, personal safety net.
Here's everything this chapter covers, in the order you'll learn it:
- Understanding HEAD as a moving pointer
- git reflog โ a log of every place HEAD has been
- Recovering commits after a bad git reset
- Recovering an accidentally deleted branch
- Dangling commits (unreferenced but not yet deleted)
- How 'lost' changes are usually still recoverable
- Creating a temporary recovery branch
- An overview of Git's garbage collection
- A safe recovery procedure step by step
- Making backups before any risky operation
2Working Example
๐ป Example: Reflog & Recovery
Bash
git reflog
git branch recovery-branch
3Best Practices & Common Pitfalls
๐ก Key things to remember:
- reflog is local-only and eventually expires (default ~90 days) โ it's a safety net for recent mistakes, not permanent storage, so recover promptly.
โ Frequently Asked Questions (FAQ)
Q What's the most important thing to understand about reflog & recovery?
Focus on: HEAD ยท git reflog ยท Recovering Deleted Branches ยท Dangling Commits. These are the core building blocks this chapter's examples are built around, and they show up repeatedly in later chapters of this course.
Q Is reflog & recovery something I'll use often in real projects?
Yes โ every concept in this chapter reflects a real, everyday part of professional Git and GitHub workflows, not just a theoretical exercise.