A deleted commit can often be recovered in Git because deleting a branch or resetting one does not immediately erase the underlying commit object. Until Git's garbage collection actually removes unreachable objects, you can usually find the commit through the reflog, the commit's hash, or git fsck --lost-found, and then attach a new branch to it. The qualification that matters is this: recovery depends on the commit still existing somewhere in the repository and on Git not having pruned it yet. A commit that was never made — for example, work discarded from the working tree before any commit existed — is not recoverable this way at all.

Why a "Deleted" Commit Usually Still Exists

Git's object model explains why recovery so often works. When you commit, Git writes the snapshot, tree objects, and a commit object into .git/objects, each content-addressed by a SHA-1 or SHA-256 hash. Branches, HEAD, and tags are just references — movable pointers stored under .git/refs (packed or loose) — to one of those commit hashes. Deleting a branch deletes the pointer, not the commit. A git reset --hard moves a branch pointer backward, again leaving the old commits in the object database.

Objects that are no longer reachable from any reference are called unreachable or dangling. Git keeps them around for a period so that ordinary mistakes do not lose data. Only git gc (which runs automatically during many everyday operations) can prune them, and even then pruning respects an expiration window that defaults to two weeks for unreachable objects. So in practice, a commit you deleted recently is almost always still present, and the question is how to locate it and reattach a reference.

The important counterpart: history that was never committed was never stored as a commit object. Unstaged or discarded working-tree edits, stashed-then-dropped work once the stash is gone, and files lost from an untracked directory generally cannot be recovered from Git alone. Recovery tools work on objects Git actually recorded, not on edits it never hashed.

Finding the Commit: Three Reliable Routes

Use the reflog first

The reflog is Git's local log of where HEAD and branch tips have pointed, recorded every time they move. For a freshly deleted branch, the branch's own reflog is the quickest source: git reflog shows the recent history of HEAD movements, and git reflog show shows where a branch tip used to be before you deleted it. Typical output lines look like a1b2c3d HEAD@{2}: reset: moving to HEAD~3 or 9f8e7d6 mybranch@{1}: commit: fix login timeout. The hash at the start of the line is the commit you want; the @{n} notation is just a relative time index.

If the reflog for the deleted branch is unavailable (for example, the repository was cloned fresh, or the branch was never checked out on this machine), git reflog for HEAD can still show the state the head was in before a reset. Reflogs are local and are not pushed to remotes, which is a key limitation: they exist only on the machine where the movements happened and only until they expire (default 90 days for reachable entries, 30 days for entries that have become unreachable).

Use the commit hash if you have it

If you copied the hash somewhere — in a terminal scrollback, a CI log, a pull request description, a chat message — that hash is enough. git show verifies the commit is intact; git branch recovered-work creates a branch pointing at it, and git switch recovered-work checks it out. From there the commit is reachable again and normal workflow resumes. A short abbreviated hash usually works too, as long as it uniquely identifies one object.

Use git fsck --lost-found when you have no other lead

When there is no reflog entry and no remembered hash, git fsck --lost-found scans the object database and reports dangling commits, as well as dangling blobs and trees. A dangling commit is one not reachable from any ref and not referenced by another object — exactly the leftover of a deleted branch or an abandoned rebase. Each reported commit hash can be inspected with git show , whose message and author date identify whether it is the one you want.

A related trick is worth knowing: a dangling commit's parent is often a normal reachable commit, so you can bridge back into history with git log --reflog or by inspecting the dangling commit's parent chain. Some people run git fsck --unreachable --no-reflogs to see objects the reflog alone does not cover, though the plain --lost-found form is usually enough, and it also drops recovered commits' info into .git/lost-found/commit/ for convenience.

What Was Actually Deleted, and What That Changes

The right recovery route depends on which pointer was removed.

Situation What still exists Usual recovery step
Branch deleted (git branch -D) Commit objects; branch reflog if it existed locally git reflog show or git fsck, then git branch
Reset moved the branch back Old tip in HEAD reflog git reflog, then git branch or git reset back
Commit amended Original commit as dangling object git reflog, git fsck --lost-found
Rebase rewrote history Old commits dangling reflog of the rebased branch, or git fsck
Stash dropped Stash commit may remain dangling git fsck --lost-found, then git stash apply
File deleted but uncommitted Nothing in Git Recover from editor or filesystem backups, not Git

An amended commit deserves emphasis because it is a very common "lost commit" case. git commit --amend does not modify the previous commit; it creates a new commit with a new hash and moves the branch, leaving the original commit unreferenced and dangling. It is recoverable exactly as a deleted branch tip is, and HEAD@{1} in the reflog often points straight at it. A rebase is the same principle at scale: the rewritten commits are new objects, and the pre-rebase sequence is recoverable via the branch's reflog or ORIG_HEAD if it is still set.

How to Make Recovery Permanent

Finding the commit is only half the job. A dangling commit is still just a candidate for garbage collection, so the next step is to give it a reference. Creating a branch is the simplest durable action, and it makes the history visible in normal tools. If you only want the content rather than the full history, git cherry-pick applies that commit's changes onto the current branch, and git checkout -- restores particular files from it. Both are useful when you do not want to resurrect a whole branch structure.

If the lost work was not just a single commit — a deleted branch with several commits on it, for instance — restoring the old tip with a branch brings its whole ancestry back, since history links commits to their parents. In that sense "recovering a commit" often recovers the sequence it belongs to.

Recovering From a Remote and From Other Local Copies

Git also preserves history on remotes, and this is an underused recovery route. If the commit was pushed before it was deleted locally, the remote may still have it, and git fetch followed by git branch / can restore from the remote-tracking branch. Even after a force-push rewrote remote history, some Git hosting providers keep the old objects accessible for a time through their web interface or by hash, so the commit can sometimes be fetched directly if the server still holds it. This is a server-dependent behavior rather than a Git guarantee, so treat it as possible, not certain, and recover from your own local object database when you can.

The same caution applies to backups and to other clones. If any colleague cloned the repository while the branch existed, their local clone still has those objects, and git fetch from them can bring the commits back into your repository. A clone is a full copy of history at the time it was made, which makes other clones a natural backup. A conspicuous failure mode is the "fresh clone" that has no reflog and no local history beyond the current remote state; in that case local recovery is impossible, and the remote or a coworker's clone is the only source.

Why Recovery Fails, and What to Do Then

Recovery fails in a small number of recognizable ways. The commit may have been pruned by git gc after the expiration window — at that point the objects are genuinely gone from the local repository. The reflog may have expired (90 days by default for reachable entries). A shallow clone (git clone --depth) deliberately omits history, and a commit that was never fetched cannot be recovered locally. The work may never have been committed at all, which is the most common cause of total loss.

When the object database has been pruned, no Git command can reconstruct the commit; the answers are backups, other clones, or the remote, and if those fail the history is unrecoverable. This is why the practical advice that follows from the mechanics is simple: commit early and often, push work that matters, and avoid git gc --prune=now on repositories where you might still need to recover something. For genuinely irreplaceable histories, regular backup of the repository — including .git — covers the one failure mode Git's own design cannot.

How the Question Is Usually Misread

Two readings of "recover a deleted commit" produce different answers, and it helps to name them. Recovering a commit object that still exists is the normal, reliable case described above; recovering changes that were never committed is not a Git recovery problem at all. Users sometimes conflate the two after losing edits in a git reset --hard, but there the files were never recorded, and Git provides no history to walk. The only avenues are editor undo history, filesystem snapshots, and backups — which is a different question with a different answer.

Likewise, a deleted commit is not the same as a deleted file. Removing a file and committing the removal stores the removal itself as a commit, and the file's prior content remains in history; git log -- and git restore --source= bring it back. The object-level mechanics are the same, but the recovery commands differ because the target is a path in a reachable commit rather than an unreachable commit.

In sum, most deleted commits are recoverable in Git because deletion of a pointer never deletes the object; use the reflog first, fall back to git fsck --lost-found and the remembered hash, and immediately reattach a branch or cherry-pick the changes so the work is safe. Recover while the objects are still present, and lean on remotes and other clones when the local repository can no longer help.