# Rollbacks and redeploys

Every successful build keeps its image. To go back, you **deploy an older build**. There is no rebuild, so you get exactly what ran before, and it is as fast as a normal deploy.

## Roll back to an earlier build

1. Open the service and go to the **Builds** tab.
2. Open the build you want. Builds that can be deployed again show **Deploy this build**. The page **Go back to an earlier build** lists them, and marks the one that is **Running now**.
3. Choose **Deploy this build** and confirm.

The deployment keeps going if you close the page. It follows the same steps as any deploy, including the [pre-deploy command and health check](/git-builds/pre-deploy-and-health-checks). If the older version does not become healthy, the one that is running keeps running.

You can do the same through the API. Choose the build and deploy it:

```bash
curl -sS -X POST "$ZAROZ_API/service-instances/$SERVICE/builds/$BUILD_ID/deploy" \
  -H "Authorization: Bearer $ZAROZ_TOKEN"
```

The token needs `services.deploy`.

## A rollback restores the settings too

A build remembers the settings it was built with. Deploying an older build puts back **its image and its deploy settings**: its start command, port, health check, pre-deploy command and the rest that came from `zaroz.toml` at that commit. You do not have to also revert the file.

Environment variables are different. They belong to the service, not to the build, so a rollback does not change them. If the old version needs a variable that you have since removed, put it back.

## Redeploy: apply a setting without a new build

A **redeploy** deploys the **current build again**. Use it after you change a deploy setting in the console, such as the start command, port, health check or pre-deploy command. Choose **Deploy this build** on the build that is running. Zaroz says it will apply the settings you changed.

Saving settings never deploys by itself. See [Build settings](/git-builds/build-settings).

## Auto-deploy after a rollback

When **Deploy each build** is on, the next push would normally deploy and replace your rollback. During an incident that would undo the rollback without warning. So after a rollback Zaroz shows:

> Auto-deploy will replace this rollback on the next push.

with a button, **Pause auto-deploy**. Choose it to keep the old version until you decide. Turn **Deploy each build** back on in **Source** when you want pushes to deploy again. The confirmation on **Deploy this build** also reminds you of this when auto-deploy is on.

A build never deploys **older** code on its own: when builds finish out of order, a newer commit is never replaced by an older one.

## How long old images are kept

For each service Zaroz keeps:

- the image of every deployment that is running now;
- the image of the previous successful deployment;
- the **10 most recent successful builds**;
- every image built in the **last 7 days**.

Older images are deleted by a daily task. A build whose image was deleted stays in the history, but **Deploy this build** is not offered. Choose **Rebuild** on its commit instead.

A rebuild of an old commit is a new build: it follows the current settings, and a base image such as `node:22` may have changed since. If you need exactly what ran before, deploy the stored image while it is still there.

A service's builder storage is capped at 20 GiB, images and cache together. The oldest images that are not protected go first. If the protected ones alone fill it, new builds stop with [`builder_storage_full`](/git-builds/troubleshooting#builder_storage_full), which names the biggest images so you can delete old builds.

## Which units move

How fast the old version leaves depends on the service's rollout rule (`rolling`, `replace_idle` or `next_start`). The build page says how many units still run the previous build. See [Pre-deploy and health checks](/git-builds/pre-deploy-and-health-checks#how-a-deploy-rolls-out).

## Related

- [Overview](/git-builds/overview): what starts a build, and what Deploy each build does.
- [Build minutes](/git-builds/billing): a rollback uses no build minutes.
