# apply

Apply a unified diff patch

Canonical URL: https://docs.paradoc.dev/cli/commands/apply/

Applies a unified diff patch to the working directory.

## Usage

```bash
paradoc apply <patch-file> [options]
```

## Arguments

| Argument     | Description         |
| ------------ | ------------------- |
| `patch-file` | Patch file to apply |

## Options

| Option      | Description                                    |
| ----------- | ---------------------------------------------- |
| `--check`   | Check if the patch can be applied cleanly      |
| `--reverse` | Apply the patch in reverse                     |
| `--dry-run` | Show what would change without modifying files |

## Description

The `apply` command reads a unified diff patch file and applies the changes to the working directory. It supports creating new files, modifying existing files, and deleting files based on the patch content.

After applying, modified artifacts are automatically validated.

## Examples

Apply a patch:

```bash
paradoc apply changes.patch
```

Check if patch applies cleanly:

```bash
paradoc apply changes.patch --check
```

Preview changes:

```bash
paradoc apply changes.patch --dry-run
```

Reverse a patch:

```bash
paradoc apply changes.patch --reverse
```

## Output

Successful application:

```
Found 2 file(s) in patch changes.patch

✓ Applied to lease-agreement.yaml
✓ Applied to checklist.yaml

Successfully applied 2 patch(es)

Modified files:
  lease-agreement.yaml
  checklist.yaml

Validating modified artifacts...
  ✓ lease-agreement.yaml is valid
  ✓ checklist.yaml is valid
```

Check mode:

```
Checking patches...
✓ lease-agreement.yaml: OK
✗ checklist.yaml: FAILED

Some patches cannot be applied (conflicts detected)
```

## See also

* [diff](/cli/commands/diff) - Generate diffs between files
* [validate](/cli/commands/validate) - Validate artifacts

## Project and patch rules

`apply` must run inside a Paradoc project. Patch paths are relative to the project root, even when invoked from a subdirectory. Application is all-or-nothing: conflicts write nothing, and a write failure rolls back prior writes. Failed validation after applying is reported as a warning. Create compatible patches with `git diff` or `diff -u`; `paradoc diff` is a display format and is not an input to `apply`.
