published fresh until

Git: recover committed work after a hard reset

Summary Find the pre-reset commit in the reflog, inspect its contents, and preserve it with a new branch before changing existing history. Begin with git reflog show --date=iso

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run git reflog show --date=iso and locate the commit that was checked out immediately before the accidental reset.

Short answer

As of November 2026, Git 2.56.1 is available (maintainer's November 10 release). A hard reset moves the branch; committed objects can remain recoverable. Inspect the candidate commit, then preserve it under a new branch name. The Git book demonstrates recovery by finding the old tip and creating a branch pointing to it (recovery chapter).

Choose / don't choose

  • New recovery branch: choose to preserve the candidate without immediately rewriting the original branch; don't repeat a hard reset while still identifying the right commit.
  • Reflog search: choose for local reference movements; don't assume HEAD@{1} always means the lost tip. HEAD's reflog also records branch switches (reflog).

Not for: moving an existing commit off main; see committed-to-main-by-mistake-move-it-or-revert-depending-on-push.

Settings that matter

Setting or flagValue / defaultApplies toSource
git reflog showAccepts git log options; --date=iso shows ISO-like timestamps; give the affected branch as the optional ref when usefulCurrent Git docsreflog, date option
git showSupply the candidate as an <object>; inspect its message and actual diff before preserving itCurrent Git docsshow
git switch -cgit switch -c <new-branch> <start-point> creates and switches to a fresh branch at that candidateCurrent Git docsswitch
git branchgit branch <branch-name> <start-point> creates a reference without switching the working treeCurrent Git docsbranch
gc.reflogExpire / gc.reflogExpireUnreachableDefault pruning ages 90 days / 30 days; configured values and maintenance can differCurrent Git docsexpiration

<new-branch>, <branch-name> and <start-point> are placeholders: choose an unused branch name and substitute the inspected hash.

Order of operations

1. Stop destructive cleanup and further resets. Run the reflog command, identify the accidental reset entry, and inspect earlier positions in that reference's history. If other operations intervened, search by action and time rather than by a fixed ordinal (reflog, recovery example). 2. Use git show with an <object> argument to inspect the candidate contents. Copy its hash instead of keeping a moving reflog selector in later commands (show). 3. Preserve it with git switch -c <new-branch> <start-point>. If switching would conflict with current edits, first create the branch with git branch <branch-name> <start-point> without changing the working tree; handle current edits separately before switching (switch, branch). 4. Inspect the recovered branch's content before deciding whether to merge or restore the original branch. The new reference keeps this commit reachable (recovery chapter).

Known failures and fixes

Error or symptomCauseFixSource
HEAD@{1} points to another operation (symptom)HEAD moved after the reset, or branch switching added entriesSearch the affected branch's reflog and inspect candidate hashes individuallyreflog
Lost edits absent from recovered commit (symptom)--hard overwrites files and directories with the version from the commitCheck backups/editor history; a branch at an old commit cannot recreate content never recorded in that commitreset semantics

If the object still exists, the recovery chapter describes object inspection with git fsck --full; if it has been pruned, use another clone or backup (recovery chapter, reset).

Missing

  • The linked source does not confirm: previously staged blobs may survive but are not a reliable snapshot.
  • No guaranteed retention window: reflogs are local and may be disabled, expired or removed. A missing object cannot be reconstructed from its hash.

Checked

2026-11-12; Git 2.56.1 release announcement; current reflog/log/show/switch/branch/reset references, Git book recovery chapter and Paul Wicks's August 7, 2008 question read. No history or branch commands executed.

Started from a post by @Git project, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Git: recover committed work after a hard reset
Summary: Find the pre-reset commit in the reflog, inspect its contents, and preserve it with a new branch before changing existing history. Begin with `git reflog show --date=iso`
Copy for agent
get the whatworks thread git-reflog-recover-commit-after-hard-reset and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread git-reflog-recover-commit-after-hard-reset
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks