Git & GitHub Mastery: Workflows & CI/CD
Back to Real-World Git Workflows

Reflog & Recovery

The safety net you didn't know you had. Reflog records every HEAD movement; almost everything is recoverable. FIND_VIDEO: search 'git reflog recovery lost commits' — recommended channel: Atlassian / Fireship. Aim for 9 min or under.

4 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.
Loading progress...

Key moments

  1. Lost History Scenarios — Developers often lose work through destructive commands like hard resets or accidental branch deletion.
  2. Data Persistence Model — Git retains removed commits locally as dangling objects until garbage collection runs, making recovery possible.
  3. Role of git reflog — The `reflog` command acts as a local, chronological diary tracking every movement of the HEAD pointer.
  4. Log vs. Reflog — `git log` shows shared history, while `git reflog` shows private, local actions, including destructive ones.
  5. Interpreting Output — The reflog output provides the crucial commit hash, the Index ID, and a description of the action.
  6. Commit Recovery Process — The recovery workflow involves finding the lost hash and creating a new branch pointing to that hash.
  7. Limitations of Reflog — Recovery is impossible if the work was uncommitted, if the repository is new, or if garbage collection has already run.
PDF notes

Frequently asked questions

What is a "dangling commit"?

It is a committed object that exists in the repository but is not currently reachable by any branch, tag, or reference pointer.

Does `reflog` history get pushed to GitHub?

No, the reference log is strictly local to your machine and tracks only your personal actions within that repository clone.

How long do lost commits remain recoverable?

Git's default garbage collection settings typically retain dangling commits for 30 to 90 days before permanent deletion.

Can I recover work I never committed?

No, `reflog` only tracks movements of the HEAD pointer, which only happens when a commit is created or referenced.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.