November 22, 2026 · 9 min read · Thomas Osayi
How to undo broken AI changes with git (and Lovable or Bolt history)
Use commits as checkpoints, git revert vs reset, branches, and Lovable and Bolt version history with GitHub sync to undo a bad AI change without losing work.
It happens to everyone who builds with AI. One prompt asks for a small tweak to the pricing page, and the reply rewrites the auth flow, renames three components and breaks the build. The next prompt, asking it to fix what it broke, makes things worse. Now you want the version from an hour ago, and you are not sure how to get it back without losing the good changes from this morning.
Here is how I undo broken AI changes, using the builder's own history first, then git, and how to set things up so the next bad prompt costs you minutes instead of a day.
How do I undo AI changes with git?
Find the commit that broke things and run git revert on it, which adds a new commit that reverses those changes while keeping everything else.
Git records your project as a series of commits, each a snapshot with a message and a unique ID. If an AI tool commits after each change, as Lovable does when GitHub sync is on, then every prompt is already a checkpoint. If you use Cursor or another editor-based tool, you need to commit yourself.
The basic flow:
- Run git log with the oneline option to see recent commits with their short IDs.
- Find the last good one and the bad ones after it.
- Run git revert followed by the bad commit's ID. Git opens an editor for the message; save it.
- If several commits in a row are bad, revert a range with git revert and the range from the last good commit to the latest, or revert them one at a time, newest first.
- Run the app and the build to confirm it works, then push.
If a revert hits a conflict, it means later commits touched the same lines. Git marks the conflicting files. Fix them, stage them with git add, and run git revert with the continue option. If it gets confusing, git revert with the abort option puts everything back as it was.
What is the difference between git revert and git reset?
git revert adds a new commit that undoes an old one and keeps history, while git reset moves the branch back in time and drops the commits after that point from the branch.
git revert
Best for: anything already pushed to GitHub, anything synced with Lovable, and any branch someone else uses.
Pros: safe, keeps a record of what happened, and works on any commit, not just the latest.
Cons: history gets an extra commit, which is a small price.
git reset
Best for: local commits you have not pushed yet, when you want them gone as if they never happened.
There are three modes worth knowing:
- Soft: moves the branch back but keeps the changes staged, ready to recommit.
- Mixed (the default): moves the branch back and keeps the changes as unstaged edits.
- Hard: moves the branch back and throws the changes away entirely.
Cons: reset rewrites history. If you reset a branch that is already on GitHub and then force push, anyone or anything that pulled the old history, including Lovable's sync, now disagrees with the remote. That is how work gets lost.
Atlassian's git tutorial on resetting, checking out and reverting has clear diagrams of both if you want to see what each command does to the commit graph.
How do I undo changes in Lovable without git?
Open the History panel, preview the version you want, and choose Revert; Lovable restores the code from that version and redeploys edge functions to match.
According to Lovable's docs at the time of writing, every change creates a version automatically. Click the History toggle in the top bar, or choose Project, then History, from the menu next to the chat input. Clicking a version opens a read-only snapshot, and View code changes shows the diff. Revert, with the tooltip Revert to this version, restores it after a confirmation.
Useful details:
- Chat history is kept, so you can reapply the good parts of later prompts.
- To try a different direction, edit a past message and choose Revert and resend.
- Bookmark versions that work, so they are easy to find later.
- Revert is all or nothing per version, and credits spent are not refunded.
- Very old versions can show the message "Cannot revert this far back in history."
The most important line in those docs: reverting does not touch database data. It restores code only, and data changes made after that version remain, including data changed by migrations. If a prompt ran a destructive migration, reverting the code will not bring the data back. That is a backup question, covered in "How to back up your Supabase or Firebase database (and test the restore)."
How do I restore an earlier version in Bolt?
Click the clock icon to open Version history, select a version to preview it, then choose Restore this version and confirm.
Bolt's help center describes a few routes at the time of writing:
- Version history: the clock-icon button opens it. Select a version, click Restore this version, and confirm with Restore version. On mobile, tap the project name, then Versions.
- Chat history: scroll up to the version, click the eye icon to preview, then the return arrow icon and Restore version.
- Download: click the project title, then Download, to get a zipped copy as your own backup.
- GitHub: if the project is connected, versioning lives in the repository, and you can import a repo state as a new Bolt project.
You can rename versions with the pencil icon and bookmark them. As with Lovable, Bolt says restoring a project version does not change your current Bolt or Supabase databases.
Why should I commit before every AI prompt?
Because a commit is a free checkpoint, and the cost of not having one is rebuilding from memory.
Builder history is good, but it lives inside one tool. Git history lives in your repository on GitHub, where any developer, editor or AI tool can use it. When I work with an AI assistant in an editor, my habit is simple:
- Commit when the app works, with a message saying what works.
- Prompt.
- Review the diff before accepting anything. If the change touched files you did not ask about, be suspicious.
- If it is good, commit it. If not, discard it with git restore on the changed files, or a reset to the last commit if nothing was committed yet.
Small commits make undoing precise. A commit that says "add discount field to checkout" can be reverted cleanly. A commit that says "lots of fixes" mixes good and bad, and reverting it throws away both.
How do branches make AI changes safer?
A branch lets you try a risky change in isolation and merge it only after it works, so the main branch, and the live app, never see the broken version.
In plain git: create a branch with git switch and the create option, do the AI work there, test it, then merge into main. If it fails, switch back to main and delete the branch. Nothing on main changed.
Lovable supports this too. Its GitHub docs say Lovable edits and syncs one branch at a time, and you can switch or create branches from the branch picker in the project's GitHub settings. New branches fork from the currently active branch, so switch to main first if that is where you want to start. Commits on other branches do not sync into Lovable until merged into the synced branch.
For a bigger change like an admin dashboard (see "How to add an admin dashboard to a Lovable app safely") or a payment flow, I always use a branch and a preview deploy. Vercel builds a preview URL for each branch automatically, so you can click through the change before it reaches customers.
What can go wrong with GitHub sync?
The main risks are force pushes that diverge the synced branch, missed sync notifications, and deleting or moving the repository.
From Lovable's GitHub docs at the time of writing:
- If the synced branch diverges, Lovable pushes its changes to a branch called lovable-sync instead. The next sync from GitHub replaces Lovable's version with the GitHub version, so Lovable-only edits can be lost. Lovable saves a backup first, which the owner can restore from the notice in the editor or from Project settings, then Git.
- If GitHub's notification is missed, the sync status shows GitHub as ahead. Pushing a new commit, even an empty one, makes Lovable sync the current state.
- If the synced branch is deleted, the project switches to a branch called lovable-fallback.
- Deleting the repository breaks the connection, and transferring the project to another workspace breaks it too.
- GitHub rejects files over 100 MB, which can stop sync.
The rule that avoids most of this: never force push to the synced branch. Use git revert on it instead. If you need to rewrite history, do it on a separate branch and merge.
What is a realistic recovery plan for an AI-built app?
Keep code history in GitHub, keep data history in backups, and know which one each problem needs.
As an illustration, picture a made-up tutoring marketplace built in Lovable with Supabase. A prompt meant to "clean up the sessions table" rewrites the booking page and runs a migration that drops a notes column. Recovery has two separate parts:
- Code: open History, preview the version before the prompt, and revert. Or, in GitHub, git revert the commits from that prompt and push. The booking page is back within minutes.
- Data: the notes column is gone in the database regardless of the code revert. On Supabase Pro, restore last night's backup into a new project and copy the notes back, or restore in place if losing today's other changes is acceptable. On the Free plan with no dump, the notes are lost.
Most founders only plan for the first part. The second part is why a nightly dump and a manual backup before any migration are worth more than any undo button.
The bottom line
To undo broken AI changes, use the builder's version history for quick rollbacks, git revert for anything already pushed or synced, and git reset only for local commits nobody else has. Commit before each prompt, try risky changes on a branch, and never force push to the branch Lovable syncs with. Remember that every undo button covers code, not data.
If an AI change has left your app in a state you cannot unwind, my Quick Fix starts at $60 for one broken change, and Fix Plus Features starts at $200 for up to three fixes plus one small feature. "Fix or rebuild your AI-built app? How to decide before you spend more" helps if the damage runs deeper.
Questions, answered in one line
What is the difference between git revert and git reset?
git revert creates a new commit that undoes an earlier one and keeps history intact, while git reset moves the branch pointer back and discards later commits from that branch.
Does reverting in Lovable undo database changes?
No, Lovable says reverting restores code and redeploys edge functions but leaves database data, including data changed by migrations, as it is.
How do I restore an old version in Bolt?
Open Version history from the clock icon, select a version to preview it, then choose Restore this version and confirm.
Can I force push to the GitHub repo Lovable syncs with?
Avoid it, because rewriting the synced branch can cause divergence and Lovable may replace its own version with the GitHub version, losing Lovable-only edits.
Can someone recover my app after AI changes broke it?
Thomas Osayi fixes a single broken change from $60 and up to three fixes plus a small feature from $200.
Sources
- Version history Lovable Docs
- GitHub integration Lovable Docs
- Rollback and backup Bolt Help Center
- Resetting, checking out and reverting Atlassian
Related articles
- Supabase auth redirect URL not working? Fix localhost, preview and production redirects
- Environment variables undefined on Vercel? Every cause and fix
- How to fix a CORS error on a Next.js API route
- Firestore "Missing or insufficient permissions": what triggers it and how to fix it
Fix, finish and launch your AI-built app
Built your app with Lovable, Bolt, v0, Replit or Cursor and got stuck? I fix the bugs, connect auth and payments, clean up the code and deploy it to production.
See the service