CodeRigor

LEARN BY DOING

Git recovery guide

Choose what happened, inspect the repository state and find a recovery route that preserves the work you need.

What happened?

The commands describe a real repository workflow. Inspect the named commit and preserve work you need before changing state.

Find and inspect the commit, then give it a branch.

Replace the placeholder with the commit you verified in your local reflog. Creating a branch adds a reference without switching branches or overwriting the working tree.

Bash
git reflog --date=iso
commit=PASTE_VERIFIED_COMMIT_ID
git show --stat "$commit"
git branch rescue "$commit"
git log rescue --oneline -5

What this can recover

Reflogs are local and expire. They record reference movement; they cannot promise recovery of objects that have already been pruned.