Git Recovery and Reflog

Git recovery patterns using reflog, ORIG_HEAD, fsck, dangling objects, and targeted reset or cherry-pick flows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Reflog Navigation
Show reflog with dates
git reflog --date=iso

# Display ref movements with timestamps.

Pretty-print reflog as log
git log -g --oneline --decorate

# View reflog entries using log output.

Show previous HEAD
git show HEAD@{1}

# Inspect earlier HEAD position.

Create branch from reflog entry
git branch recovered HEAD@{3}

# Preserve a reflog-discovered commit.

Reset to earlier HEAD
git reset --hard HEAD@{1}

# Restore prior branch tip exactly.

## Common Recovery Scenarios
Recover after hard reset
git reset --hard ORIG_HEAD

# Restore previous HEAD after disruptive operation when ORIG_HEAD is available.

Recover deleted branch from reflog
git checkout -b recovered <dangling_or_reflog_commit>

# Recreate a branch from recovered commit ID.

Undo failed merge
git reset --merge ORIG_HEAD

# Restore pre-merge state when merge --abort is unavailable.

Find dropped stash commits
git fsck --no-reflog | grep dangling

# Locate dangling stash-like commits after accidental drop.

Cherry-pick recovered commit
git cherry-pick <recovered_commit_sha>

# Apply recovered work onto a clean branch.

## Dangling Objects and Inspection
Check repository integrity
git fsck --full

# Validate objects and refs.

List dangling objects
git fsck --full --dangling

# Find unreferenced commits, trees, and blobs.

Inspect dangling commit
git show <dangling_commit_sha>

# Review commit content before recovery.

Inspect dangling blob
git cat-file -p <blob_sha>

# Print blob content if a file was lost.