---
title: schema diff
description: Compares two schemas, each a space or a local entry file, and reports the blocks, folders, and datasources that differ.
url: https://www.storyblok.com/docs/tooling/cli/schema/diff
---

# schema diff

Compares two schemas and reports the blocks, folders, and datasources that `--to` adds, changes, or removes compared to `--from`. Each side is either a space ID or a local entry file. Run it before [`schema push`](/docs/tooling/cli/schema/push) to preview a push, or in CI to detect changes made to a space in the Storyblok UI.

## Prerequisites

-   To compare a space, log in with [`storyblok login`](/docs/tooling/cli/account/login).
-   To compare a local schema, an entry file that exports schema definitions authored with [`@storyblok/schema`](/docs/libraries/js/schema).

## Usage

```bash
storyblok schema diff --from <space-id|entry-file> --to <space-id|entry-file> [flags]
```

## Flags

| Flag | Type | Description |
| --- | --- | --- |
| `--from` | string | _Required._ The base schema: a space ID or a path to a schema entry file. |
| `--to` | string | _Required._ The target schema: a space ID or a path to a schema entry file. |
| `--exit-code` | boolean | _Optional._ Exit with `1` when the schemas differ and `2` on error. Refer to [Exit codes](#exit-codes). |

## Examples

```bash
# Preview what pushing the local schema changes in a space
storyblok schema diff --from 123456 --to src/schema/schema.ts
# Fail a CI job when the space drifted from the local schema
storyblok schema diff --from 123456 --to src/schema/schema.ts --exit-code
```

## Exit codes

By default, the command exits with `0` whether or not the schemas differ. With `--exit-code`, the exit code reports the result, like `git diff --exit-code`:

| Exit code | Meaning |
| --- | --- |
| `0` | The schemas match. |
| `1` | The schemas differ. |
| `2` | The command failed. |

## Pagination

-   [Previous: prune](/docs/tooling/cli/reports/prune)
-   [Next: init](/docs/tooling/cli/schema/init)
