How to Undo Changes an AI Coding Assistant Made: What Git Recovers, What the Platform Recovers, What Is Gone

It worked an hour ago. Then the assistant rewrote four files and now nothing runs. What you can get back was decided before any of that happened.

Six ways of losing work, each destroyed for real and then recovered: four came back because the content had reached git's object store, two were gone because nothing was ever written to it, and separately one commit per session means a revert undoes five files and thirteen edits while one commit per prompt undoes exactly the change that broke things

An hour ago the app worked. Then you asked for one more feature, the assistant rewrote four files, and now nothing runs — and you cannot tell which of the four changes did it.

Most advice at this point is “use version control”, which is true and useless, because the question is not whether you should have. It is what you can get back right now.

So we took six ways of losing work, carried each one out for real in a throwaway repository, and tried to recover. Four came back. Two did not, and the reason has nothing to do with how careful anyone was.

Watch it instead

Versioning is number 11 in our countdown of what actually goes wrong for people building with AI.

Video: We Analyzed 130,000 Vibe Coder Posts. These Are the Problems That Actually Hurt.
Watch it instead We Analyzed 130,000 Vibe Coder Posts. These Are the Problems That Actually Hurt.
From the Back4app channel. This guide is the long version of its eleventh position; the countdown itself is in the companion post. Open on YouTube →

What actually survives?

Four of the six. Here is the whole result, with the command that brings each one back:

Six ways to lose work: four recoverable through the reflog or git fsck, two gone because nothing was ever written to the object store

The pattern is not about severity. A force-deleted branch and a dropped stash both come back, while a quiet git checkout -- file — the gentlest-looking command on the list — destroys work permanently.

What separates them is whether the content was ever written into git’s object store. That store is content-addressed and append-only in practice: once something is in it, removing the reference that points at it does not remove the thing.

How we measured: each scenario runs in its own fresh repository with gc.auto disabled, the loss is performed for real, and recovery is attempted and verified by reading the content back. Deterministic across three consecutive runs — the script is in the repo.

What is the one command that decides it?

git add. It is normally described as “staging for the next commit”, which hides what it actually does: it writes your file into the object store immediately, as a permanent object.

That is why this comes back after a hard reset:

git add app.txt          # the content is now an object
git reset --hard HEAD    # the reference is gone, the object is not
git fsck --lost-found    # dangling blob 3f2a...
git cat-file -p 3f2a     # your file, printed

And this does not:

# edited app.txt, never added
git reset --hard HEAD
git fsck --lost-found    # nothing. 0 dangling objects.

A dropped stash comes back. A quiet “discard my edits” does not.

So the habit worth building is not “commit more”, which people resist because a commit feels like a statement. It is add more — a keystroke with no message, no ceremony, and a safety net attached.

How do you undo one bad change out of twenty?

By having committed them separately, which is the part nobody does in the moment.

We ran the same thirteen edits twice. First as one commit at the end of the session, the way most people work:

git revert HEAD   →  undoes 5 files and 13 edits — including the 12 that were fine

Then with a commit before each prompt:

git revert 3c2a682  →  undid exactly that change — the other 12 are untouched

Same work, same edits, same tool. The only difference is where the boundaries were, and the boundaries were decided before anyone knew which change would break.

What about the thing that is actually running?

Git protects your source. It does nothing for the version your users are hitting right now, and during an incident that is the one that matters.

This is the second half of versioning, and it has a different shape. You do not want to rebuild the last good version under pressure — you want it to still exist, so that going back is a selection rather than a project.

A platform that keeps every deploy gives you that: the previous build is still there, so a bad release is reversed in the time it takes to pick it. Your source history tells you what changed; the deploy history lets you stop the bleeding first and find out afterwards.

How long do you have?

Less than forever, and the clock is git’s housekeeping rather than the calendar. Unreachable objects survive until garbage collection removes them: by default, reflog entries live 90 days and unreachable objects two weeks.

In practice, recovery is a same-day operation. Anything that triggers a gc — and many ordinary commands do, quietly — reduces what is left to find.

Which is the argument for trying immediately rather than reading about it first. git reflog costs nothing and answers the question in one screen.

What should you do first?

Right now, before the next prompt: git add -A. If something is about to be destroyed, that one command is the difference between a bad afternoon and a lost one.

Then change where your commits fall. One before each prompt, with a throwaway message — wip, the prompt itself, anything. You are not writing history for anyone to read; you are placing boundaries you can revert to.

And if you have already lost something, do not start retyping it. Run git reflog, then git fsck --lost-found. Four times out of six in our test, the work was still there.

Tagsgitversion-controlai-codingrollbackrecoverydeployment

Frequently asked questions

Can I recover code after git reset --hard?

It depends on one thing: whether the content ever reached git's object store. A committed change comes back through the reflog. A change you had run git add on comes back through git fsck --lost-found, because add writes a real object. A change that only ever existed in the file is gone, and we confirmed that — fsck found zero dangling objects.

What is the single most useful habit when working with an AI assistant?

Commit before each prompt rather than after each feature. We measured the difference: with one commit for a session, reverting it undid 5 files and 13 edits, 12 of which were fine. With one commit per prompt, a revert undid exactly the change that broke things and left the other 12 untouched.

I dropped a git stash. Is it really gone?

No. A stash is a commit, so dropping it only removes the reference. git fsck --unreachable lists the commit and git stash apply with that hash brings it back. We destroyed and recovered one to confirm it. The same is true of a branch deleted with -D: the commit survives in the reflog.

Does a managed platform help with rollback?

It covers the half git does not: what is actually running. Versioned deploys mean the last working build is still there, so recovering from a bad release is selecting it rather than rebuilding it. Git protects your source; deploy versioning protects your users while you work out what went wrong.

How long do I have to recover a lost commit?

Longer than people fear, but not forever. Unreachable objects survive until git's garbage collection removes them — the default grace period is 90 days for reflog entries and 2 weeks for unreachable objects. The practical rule is that recovery is a same-day operation, and it gets less likely the more git housekeeping runs in between.

Further reading

Reviewed & verified by Back4app Engineering, Editorial review at Back4app

Tested Oct 27, 2026 — Local: git 2.54.0 on macOS, arm64 · Each scenario in its own throwaway repository with gc.auto disabled · Backend: Back4app, free plan.

Changelog

  • Oct 30, 2026 — The companion repository is not published yet, so the link to it and the button were removed; they come back when it is.
  • Oct 28, 2026 — The companion repository is published, so the button and the inline link to it are back.

More from Back4app Engineering

Containers · error-guide

Why Your App Works Locally and Crashes When You Deploy It [Full Repo]

Backend · tutorial

Why Your App Gets Slow With Only 80 Users: a Missing Index and an N+1 Loop, Measured

Backend · report

Why Vibe-Coded Apps Break: 13 Problems From 130,000 Posts, Ranked, With the Fix for Each