Skip to content
rajin

28Reflog, fsck and disaster recovery

advanced25–30 minHandbook pp. 61–62 Not started

Warm-up · from “Reachability and garbage collection”

What does reachability depend on?

No notes: write what you remember, then check. Recalling before reading is what makes it stick.

The problem

A reset removed a commit from log, and a staged-only file was lost. Different evidence survives each accident.

After this lesson you can

  • Find recent ref movements.

  • Recover a commit by creating a ref.

  • Recover staged bytes when their blob remains.

Key terms

Full glossary

Say what each term means, then open it to check.

  • Reflog · new in this lesson

    Local log of ref updates when enabled.

  • HEAD · from lesson 14

    Current symbolic branch reference or detached commit identity.

  • Commit · from lesson 7

    Object identifying a root tree, parent(s), metadata and message.

  • Blob · from lesson 5

    Object storing file contents without a filename.

  • Ref · from lesson 3

    Name identifying an object; branch refs usually identify commits.

Visual mental model

  1. Missing commitreflog → rescue branch
  2. Missing staged bytesfsck → inspect blob → recover file

Build the mental model

Reflogs record local ref updates when enabled. git reflog shows recent HEAD positions; git reflog BRANCH can show that branch's history if its log exists. Entries expire, can be deleted and are not transferred by ordinary push or clone. Inspect the message and ID rather than assuming HEAD@{1} is the desired point. Recover a commit by creating a new branch first; inspect before resetting any existing branch.

SimulationReset moves the ref, the commit survives

A simplified model for building intuition. It does not read your sandbox; use the terminal for real behaviour.

Under the hood

For a staged-only file, the blob may survive even though it was never committed. git fsck --full --no-reflogs --unreachable can find candidate objects. Inspect with git cat-file -p ID and redirect confirmed blob contents to a new safe path. Blobs do not carry filenames. Never-staged bytes are normally not in Git unless they happen to match other stored content; editor history or backups may help. Avoid gc, prune and further destructive edits during recovery.

Common mistake · important nuance

This lab deliberately loses data in a disposable repository. In real recovery, make a copy of metadata and working files first.

Move between parts freely. Completion counts only what you verify and answer.