> ## 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 v2, at app.newly.app and in Newly for Mac, 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.
</Note>

## 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.

<Steps>
  <Step title="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.
  </Step>

  <Step title="Find the message">
    Scroll to the message whose result you want to go back to.
  </Step>

  <Step title="Select Restore to here">
    Select **Restore to here** under that message.
  </Step>

  <Step title="Continue chatting">
    When it's done, you'll see "Restored that version. Your next message will continue from it."
  </Step>
</Steps>

## 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](/build/sleep-and-limits).
* **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](/code/where-your-code-lives).
* **It doesn't change `main`.** If you already promoted to `main`, promote 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](/help/getting-help).

## Credits

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

## 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](/help/getting-help) and include the project link. |

## Related pages

<CardGroup cols={2}>
  <Card title="Where your code lives" icon="code-branch" href="/code/where-your-code-lives">
    Saved versions, branches and Promote to main.
  </Card>

  <Card title="Chatting with the agent" icon="comments" href="/build/chatting-with-the-agent">
    Sending, stopping and queueing messages.
  </Card>
</CardGroup>
