When people search for "how to get local changes back get it," they usually mean one thing: their uncommitted or stashed work has vanished from Git, and they need it returned to the working tree. The good news is that Git almost never destroys anything immediately. Uncommitted edits that were overwritten by a checkout, a reset, or a stash-and-drop are usually still recoverable from the index, the reflog, or dangling objects — as long as you act before garbage collection runs or you overwrite the working tree again. The key condition is that you must not run commands that permanently discard the data before you have identified where it went.

The phrase itself is garbled, so this article treats it as covering the common real situations: edits lost to git checkout or git restore, work wiped by git reset --hard, stashes that were dropped or never applied, commits that fell off a branch, and changes lost in a crashed or interrupted editor session. Each has a different recovery path, and mixing them up wastes the one window you have.

Preconditions: Protect the Evidence Before You Type Anything

Before touching recovery commands, freeze the situation. Every recovery method below depends on the data still existing somewhere in .git, and a few careless commands will overwrite it.

1: Stop working in that repository until you have copied what you can. Don't pull, don't merge, don't rebase, don't run git gc or git prune, and don't force-checkout another branch. 2: Make a full copy of the repository directory, including the hidden .git folder. A simple filesystem copy is enough; it preserves every object, the reflog, and the index state as they were. 3: Check the obvious places first: open your editor's local history or undo buffer (many editors keep their own timeline independent of Git), and check whether the changes were saved anywhere else on disk — a scratch file, a .orig file from a merge, or a backup directory. 4: Confirm your Git version and current state with git status and git --version. Recovery commands like git restore are newer than the old git checkout syntax, and knowing the version tells you which output formats to expect.

Success at this stage means you have a byte-for-byte backup and haven't run any destructive command. A quick check: the backup directory's size should roughly match the original, and git status in the original should still show the same output it did before you started.

First Case: Edits Overwritten by Checkout, Restore, or Switch

If you discarded tracked modifications with git checkout -- file, git restore file, or git switch --discard-changes, the working-tree copy is gone, but Git's index and the temporary object store often still have the content — particularly if the file was ever git added at any point, even briefly.

If the changes were staged at some point, run git fsck --lost-found. This probes for unreachable objects and writes them into .git/lost-found/. Blobs from index operations land in .git/lost-found/other/. Inspect each file with git cat-file -p or just open the files directly — they are raw content with no filename attached, so grep for a distinctive string from the lost code. If the changes were never staged, the situation is harder. The working tree is not a Git object, so Git has no copy. Your editor's undo history, swap files (Vim's .swp, Emacs autosave, VS Code's local history panel), or an OS-level backup or snapshot service are the realistic sources. This is the failure case people most often hit, and it is why staging — even momentarily — is cheap insurance.

The check for success: the recovered file should diff cleanly against the current version, and the content should contain the specific lines you remember writing. If git fsck returns nothing useful and no editor history exists, stop here for this file; further Git commands won't recover it.

Second Case: git reset --hard Wiped the Working Tree

A hard reset moves the branch pointer and overwrites the working tree, but the commit it pointed to before the reset is still referenced by the reflog. The reflog is your map of every position HEAD has held.

1: Run git reflog and look at the top entries. The line just before your reset command shows the commit HEAD was on. 2: Note its hash, then inspect it with git show and git diff against the current HEAD to see exactly what changed. 3: Restore it with git reset --hard if you want the whole state back, or git checkout -- path/to/file to pull back only the files you need. 4: If the state you want is a mix — some files from the old commit, some current — use git restore --source= on the selected files.

Success check: git log --oneline -3 and git status should show the branch back where it was, with a clean tree and the expected files present. If the reflog entry you want is more than 90 days old by default, it may already be expired — see the expiry section below.

Third Case: Dropped or Never-Applied Stashes

Stashes are commits, which is why they survive most accidents. A dropped stash is still reachable until it expires or is pruned.

List what still exists with git stash list. If the stash you want is there but you thought you lost it, just apply it: git stash apply stash@{n} (applies and keeps the stash) or git stash pop (applies and removes it). If git stash list is empty but you dropped something, use git fsck --unreachable --no-reflogs and look for commit objects. Stash commits have a distinctive structure: a merge commit whose message begins with WIP on or On :. You can feed a candidate hash to git show and confirm it's the stash by its message and parent structure. Restoring a found stash commit: since it's a stash-shaped merge, the simplest route is git stash apply , which works on stash commits even when they're not in the stash list. You can also check it out as a detached HEAD to inspect before applying.

The success check: git stash list shows the entry after recovery (applying doesn't necessarily re-add it, so confirm with git status that the changes are in your working tree), and conflicts, if any, appear in the usual <<<<<<< markers rather than silently overwriting work.

Fourth Case: Commits That Fell Off a Branch

If a rebase, amend, or branch deletion left commits unreachable, the reflog and git fsck are again the tools. For a deleted branch, git reflog won't show the deleted branch's tip directly, but the commits may still appear as HEAD@{n} entries if you checked them out before deletion. Otherwise git fsck --unreachable lists them, and git branch recovered reattaches the work to a named branch. For an amended commit where you want the pre-amend version, git reflog shows the old commit hash, and git show displays the original message and tree.

One caution: after a rebase, dozens of unreachable commits can appear, most of them intermediate steps you don't want. Match on commit messages and file contents rather than guessing by hash order.

Fifth Case: Changes Lost in a Crash or Interrupted Session

This isn't strictly a Git recovery path, but it's the most common reason people search this phrase. Modern editors and IDEs keep their own history: VS Code's Timeline view and local history, JetBrains IDEs' Local History, Vim's swap and undo files, and OS-level file versioning. Check those before assuming Git has the answer. If a pre-commit hook or an interrupted git commit was involved, the staged state may still be in the index — git diff --cached shows it, and git checkout-index -a can write it back out.

Understanding Expiry: When Recovery Is No Longer Possible

Git's safety net has a shelf life. Reflog entries expire after 90 days by default for reachable entries and 30 days for unreachable ones (gc.reflogExpire and gc.reflogExpireUnreachable). Unreachable objects are pruned by git gc after a two-week grace period by default (gc.pruneExpire). On a busy or shared machine, gc can run automatically or be triggered by a git pull, which is another reason to work from your backup copy rather than the live repository. If the objects are gone and no editor or filesystem history exists, the data is genuinely unrecoverable by ordinary means, and the honest move is to redo the work rather than keep probing.

Preventing the Next Loss

None of these procedures is pleasant, and the reliable fix is procedural. Stage small increments — git add -p lets you stage hunks selectively and creates recoverable blobs without committing. Commit more often than feels tidy; a messy history is cheaper than a lost afternoon. Prefer git stash push -m "description" over leaving changes floating, and never drop a stash until the work is merged or backed up elsewhere. Finally, keep the reflog defaults generous on machines where you do heavy interactive rebasing, and avoid git gc --prune=now unless you're certain nothing needs recovering.

Success here isn't a command; it's the habit of having a recoverable object for any change you care about before you run anything that could overwrite the working tree.

FAQ

Does git reset --hard delete my commits permanently? No — it moves the branch pointer and overwrites the working tree, but the previous commits stay in the reflog and as unreachable objects until they expire or are pruned. git reflog is the first place to look.

Can I recover changes that were never staged or committed? Only from outside Git: editor undo history, swap files, local history features, or filesystem snapshots. Git has no object for content that never entered the index, which is why staging even briefly matters.

Is git fsck --lost-found safe to run? Yes. It only reads the object database and writes found objects into .git/lost-found/; it does not modify your branches or working tree. Run it on your backup copy if you want extra caution.

What if the reflog entry I need is older than 90 days? It has likely expired under default settings, and the objects may have been pruned. Check your gc.reflogExpire and gc.pruneExpire configuration and whether a git gc has run since; if the objects are gone, recovery through Git isn't possible.