# Patch files

Use the `--patch-only=<patch-file>` argument to define a patch file - Diffblue Cover will only write tests for the code changes defined in the patch file (any class in the patch and any related/dependent classes).

## Command line argument

**Usage:** `--patch-only=<patch-file>`

**Alternative:** `-p=<patch-file>`

**Example:** `--patch-only=path/to/file.patch`

* Use diff or a similar tool to create a patch file for your changes in your project - for example:\
  `git diff origin/develop > file.patch`.
* For a multi-module project, generate the patch at the root of the project and provide the absolute path to the patch file, using `--working-directory` with the relative path to the module. The same patch file can be used for each module.
* For a project without modules, or a project where tests will only ever be created for a single module, where `--working-directory` is not used, the relative path to the patch file for the project or module only may be used - for example:

```
    cd Module
    git diff origin/develop --relative > file.patch
```

* The `--patch-only` argument only accepts files in UTF-8 encoding. If using PowerShell on Windows, use the following command to get the patch in UTF-8 instead of the default UTF-16:

```
    git diff origin/develop | out-file file.patch -encoding utf8
```

## Create a patch file

The exact patch file you need depends on your setup, but here are some examples using `git diff`. The variable `DIFFBLUE_PATCH` represents the name of your patch file.

***

For a patch containing commits newer than the project's origin (i.e. the corresponding branch on the remote repository your local branch was created from):

```groovy
git diff $(git rev-parse --abbrev-ref HEAD)...HEAD > $DIFFBLUE_PATCH
```

***

For a patch containing commits on your branch newer than those on the local copy of `TARGET_BRANCH` (e.g. where `TARGET_BRANCH` is `develop`):

```groovy
git diff TARGET_BRANCH...HEAD > $DIFFBLUE_PATCH
```

***

For a patch containing commits on your branch newer than those on the remote host `TARGET_BRANCH` (e.g. where `REMOTE` is `origin` and `REMOTE/TARGET_BRANCH` is `origin/develop`):

```groovy
git fetch REMOTE
git diff REMOTE/TARGET_BRANCH...HEAD > $DIFFBLUE_PATCH
```

***

For a patch containing only currently uncommitted changes:

```groovy
git diff > $DIFFBLUE_PATCH
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cover-docs-preview.diffblue.com/features/cover-cli/writing-tests/patch-files.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
