# Compare file versions

Every save keeps a version of the file.

## Before you start

You need `app/page.tsx`, saved more than once. See [Edit files](/docs/projects/files.md).

## Compare versions

**Studio**

1. Right-click the file's tab, `page.tsx`.
2. Click **Versions**. You should now see up to 30 of the file's versions, newest first, each by its time under its day, such as Today.
3. Click the last version in the list. It opens in a tab of its own.
4. Open **Editor actions**.
5. Click **Compare draft**. You should now see a tab that reads `page.tsx ↔ Draft`, with the changed lines marked.
6. Click the last version in the list again.
7. Open **Editor actions**.
8. Click **Select for compare**.
9. Click the newest version.
10. Open **Editor actions**.
11. Click **Compare with selected**. You should now see a tab that reads `page.tsx ↔ page.tsx`, with the changed lines marked.

**API**

1. Set `PROJECT` to your project's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export PROJECT=<id>`.
2. List the file's versions, newest first, with your [API key](/docs/authentication/api-keys.md). You should now see up to 20 versions, each with an `id`, and in `page_info.next` the cursor for the next 20, or `null` when there are no more:

```bash
curl https://api.veryfront.com/projects/$PROJECT/files/app%2Fpage.tsx/versions \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

3. Set `VERSION_ID` to the `id` of the version you want: `export VERSION_ID=<id>`. To reach older versions, list them again with `?cursor=` and that `page_info.next`.
4. Get it. You should now see the file as it was, in `content`:

```bash
curl https://api.veryfront.com/projects/$PROJECT/files/app%2Fpage.tsx/versions/$VERSION_ID \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

### Try it in a sandbox

```playground
step: A file saved twice | npm create -y veryfront@latest support-desk -- --template minimal --yes && cd support-desk && npx veryfront push --yes && sed -i 's/Welcome to Veryfront/Support desk/' app/page.tsx && npx veryfront files put app/page.tsx --from app/page.tsx
step: Set PROJECT | export PROJECT=$VERYFRONT_PROJECT_ID
step: List the versions | curl https://api.veryfront.com/projects/$PROJECT/files/app%2Fpage.tsx/versions -H "Authorization: Bearer $VERYFRONT_API_KEY"
step: Set VERSION_ID to the oldest | export VERSION_ID=$(curl -s https://api.veryfront.com/projects/$PROJECT/files/app%2Fpage.tsx/versions -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r '.data[-1].id')
check: curl https://api.veryfront.com/projects/$PROJECT/files/app%2Fpage.tsx/versions/$VERSION_ID -H "Authorization: Bearer $VERYFRONT_API_KEY"
expect: Welcome to Veryfront
```

These calls read the file on the main branch. On another branch, add `?ref=branch:<name>` to both URLs, with the branch's name as it shows under **Branches**.

## With MCP

1. Call `veryfront__list_file_versions` with `{ "project_reference": "my-project", "file_path": "app/page.tsx" }`. The project reference is its slug or its ID. On another branch, also pass `"ref": "branch:<name>"`, here and in the next call. While the answer's `page_info.next` is not null, call it again with that value as `cursor` to reach older versions.
2. Call `veryfront__get_file_version` with the same `project_reference` and `file_path`, and one entry's `id` as `version_id`. It worked when the answer holds the file's `content` as it was.

## Next steps

* [Create a branch](/docs/projects/create-branch.md)
* [Merge a branch](/docs/projects/merge-branch.md)
