> ## Documentation Index
> Fetch the complete documentation index at: https://docs.newly.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Undo and Restore to here

> Go back to an earlier version of your app's code with Undo or Restore to here.

Newly (app.newly.app) saves a version of your code after each agent turn that changes files. You can go back to one of those versions with **Restore to here**, or step back one version with **Undo**.

> [!NOTE]
>
> "Undo changes your app's code, not its data." Rows in your database and files your app stored aren't rolled back.

## Restore to here

**Restore to here** appears under each of your messages that produced a saved version. It takes your code back to how it was right after the agent finished that turn.

**1. Stop the agent if it's working**

You can't restore while a turn is running. **Restore to here** is greyed out until the agent finishes or you stop it.

**2. Find the message**

Scroll to the message whose result you want to go back to.

**3. Select Restore to here**

Select **Restore to here** under that message.

**4. Continue chatting**

When it's done, you'll see "Restored that version. Your next message will continue from it."

## Undo

When Developer mode is off, an **Undo** button sits at the top right of the window while a chat is open. Hover over it to see what it does: "Goes back to the version before your last change."

**Undo** stays greyed out until the chat has at least two saved versions. Until then, hovering over it adds "This session has no earlier version yet."

## What happens when you restore

* **The chat parks first.** Newly parks the chat, restores the code, and your next message continues from the restored version. See [Parked chats and limits](https://docs.newly.app/build/sleep-and-limits.md).
* **A restore adds a new version.** Your later versions aren't deleted. The restore is saved on top of them, so you can undo an undo by selecting **Restore to here** on a later message.
* **It changes `dev` for the whole project.** By default, all chats in a project work on the same `dev` branch, so every chat sees the restored code. See [Where your code lives](https://docs.newly.app/code/where-your-code-lives.md).
* **It doesn't change `main`.** If you already updated `main`, update it again after restoring if you want `main` to match.
* **Your chat stays as it was.** Restoring changes code only. The messages above and below stay in the chat.

## What isn't restored

Restoring brings back your app's code. It doesn't roll back:

* data in your app's database, such as users or records your app created
* files your app uploaded or stored
* anything outside the project's code

If you need to fix data, ask the agent for help or [contact support](https://docs.newly.app/help/getting-help.md).

## Credits

Restoring doesn't run the agent, so it doesn't use credits. Only the messages you send afterwards do. See [How credits work](https://docs.newly.app/billing/how-credits-work.md).

## If a restore fails

| Message | What to do |
| - | - |
| "The agent is still working. Stop it before restoring a version." | The chat couldn't be parked because a turn is still running. Stop the turn, then try again. |
| "There's no earlier version to undo yet." | You selected **Undo**, but the chat has no earlier saved version to go back to. |
| "Couldn't restore that version." | Try again in a moment. If it keeps happening, [contact support](https://docs.newly.app/help/getting-help.md) and include the project link. |

## Related pages

> [card] [Where your code lives](https://docs.newly.app/code/where-your-code-lives.md)
>
> Saved versions, branches and updating main.

> [card] [Chatting with the agent](https://docs.newly.app/build/chatting-with-the-agent.md)
>
> Sending, stopping and queueing messages.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.