---
name: "diff3"
section: "1"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd", "openbsd", "macos"]
url: "https://new.carta.tech/diff3"
---

# diff3(1)

3-way differential file comparison

## NAME

**diff3** – 3-way differential file comparison

## SYNOPSIS

**diff3** \[**-3AaEeimTXx**\] \[**-****-diff-program** *program*\] \[**-****-strip-trailing-cr**\] \[**-L** \| **-****-label** *label1*\] \[**-L** \| **-****-label** *label2*\] \[**-L** \| **-****-label** *label3*\] *file1* *file2* *file3*

**diff3** \[**-****-help**\] \[**-****-version**\]

## DESCRIPTION

The **diff3** utility compares the contents of three different versions of a file, *file1*, *file2* and *file3*, writing the result to the standard output. The options describe different methods of merging and purging the separate versions into a new file. **diff3** is used by [rcs(1)](/rcs/1.md) to merge specific versions or create new versions.

The options are as follows:

- **-3**, **-****-easy-only**

  Produces an output script suitable for [ed(1)](/ed/1.md) with changes specific only to *file3*.

- **-A** **-****-show-all**

  Output all changes, bracketing conflicts.

- **-a**, **-****-text**

  Treat all files as ASCII.

- **-E**, **-****-show-overlap**

  - **-X**

  Similar to **-e** and **-x**, respectively, but treat overlapping changes (i.e., changes that would be noted with ==== in the normal listing) differently. The overlapping lines from both files will be inserted by the edit script, bracketed by "\<\<\<\<\<\<" and "\>\>\>\>\>\>" lines.

- **-e**, **-****-ed**

  Produces output in a form suitable as an input script for the [ed(1)](/ed/1.md) utility. The script may then be used to merge differences common between all three files and differences specific to *file1* and *file3*. In other words, the **-e** option ignores differences specific to *file1* and *file2*, and those specific to *file2* and *file3*. It is useful for backing out changes specific to *file2* only.

- **-****-help**

  Prints usage information and exits.

- **-i**

  Appends 'w' and 'q' [ed(1)](/ed/1.md) commands.

- **-L**, **-****-label**

  Defines labels to print instead of file names *file1*, *file2* and *file3*.

- **-m,** **-****-merge**

  Merge output instead of generating ed script.

- **-T,** **-****-initial-tab**

  In the normal listing, use a tab instead of two spaces at the beginning of each line. In modes that produce an [ed(1)](/ed/1.md) script, this option changes nothing.

- **-x,** **-****-overlap-only**

  Produces an output script suitable for [ed(1)](/ed/1.md) with changes specific only to all three versions.

- **-****-diff-program** *program*

  Use *program* instead of the default [diff(1)](/diff/1.md) to compare files.

- **-****-strip-trailing-cr**

  Strip trailing carriage return on input files.

- **-****-version**

  Prints version information and exits.

The **-E** option is used by RCS [merge(1)](/merge/1.md) to ensure that overlapping changes in the merged files are preserved and brought to someone's attention.

For example, suppose lines 7-8 are changed in both *file1* and *file2*. Applying the edit script generated by the command

```
$ diff3 -E file1 file2 file3
```

to *file1* results in the file:

```
lines 1-6
of file1
<<<<<<< file1
lines 7-8
of file1
=======
lines 7-8
of file3
>>>>>>> file3
rest of file1
```

The default output of **diff3** makes notation of the differences between all files, and those differences specific to each pair of files. The changes are described by the commands necessary for [ed(1)](/ed/1.md) to create the desired target from the different versions. See [diff(1)](/diff/1.md) for a description of the commands.

- \====

  The lines beneath this notation are ranges of lines which are different between all files.

- \====*n*

  The lines beneath this notation are ranges of lines which are exclusively different in file *n*.

## EXIT STATUS

The **diff3** utility exits with a status of 0 on success and \>1 if an error occurred. Additionally, if the **-A**, **-E**, **-L**, **-m**, or **-X** flags were specified, it exits with a status of 1 if conflicts were found.

## SEE ALSO

[diff(1)](/diff/1.md), [ed(1)](/ed/1.md), [merge(1)](/merge/1.md), [rcs(1)](/rcs/1.md), [sdiff(1)](/sdiff/1.md)

## HISTORY

A **diff3** command appeared in Version 7 AT&T UNIX.

## BUGS

The **-e** option cannot catch and change lines which have ‘.’ as the first and only character on the line. The resulting script will fail on that line as ‘.’ is an [ed(1)](/ed/1.md) editing command.
