Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

P4 CLI Documentation | 2025.2

# p4 diff2 (graph)

Diff utility for comparing the content at two repo paths. (For comparing workspace content to repo content, see p4 diff (graph).)

## Syntax

    p4 diff2 [options] fromFile[@sha1|@reference] tofile[@sha1|@reference]

Syntax and naming conventions

## Description

p4 diff2 runs on the server to compare one set of graph repo files (the 'source') to another (the 'target'). Source and target file sets can be specified on the 'p4 diff2' command line.

fromFile and toFile can include @sha1 or @reference specifiers. By default, the head revisions are diffed.

This command precedes each diffed file pair with a header line of the

following form:

`==== source#rev (type) - target#rev (type) ==== summary`

A source or target file shown as <none> means there is no file at the specified name or reference to pair with its counterpart. The summary status is one of the following: identical means file contents and types are identical, types means file contents are identical but the types are different, and content means file contents are different.

## Options

Option | Description
--- | ---
`-d`options`` | Runs the diff routine with one of a subset of the standard UNIX diff options.
`-Od` | Limit output to only those files that differ.
`-q` | Quiet diff. Display only the header; if file1 and file2 are identical, display only "``file1` - no differing files`" as the output.
`-u` | Generate unified output format, showing added and deleted lines with sufficient context for compatibility with the `patch(1)` utility. Only those files that differ are included. File names and dates remain in P4 Server syntax.

### The diff options supported by `p4 diff2`

Option | Description
--- | ---
`-dn` | RCS output format, showing additions and deletions made to the file and associated line ranges.
`-dc[`num`]` | context output format, showing line number ranges and num lines of context around the changes.
`-ds` | summary output format, showing only the number of chunks and lines added, deleted, or changed.
`-du[`num`]` | unified output format, showing added and deleted lines with num lines of context, in a form compatible with the `patch(1)` utility.
`-dl` | ignore line-ending (CR/LF) convention when finding diffs
`-db` | ignore changes made within whitespace; this option implies `-dl`.
`-dw` | ignore whitespace altogether; this option implies `-dl`.

- To pass more than one option to the diff routine, group them together. For example:

      p4 diff2 -dub file1 file2

  specifies a unified diff that ignores changes in whitespace.

- The header line of a unified diff produced with the `-du` option for `patch(1)` use displays the diffed files in P4 Server syntax, not local syntax.

- When `p4 diff2` is used to diff `binary` files, the line

      ... files differ ...

  is printed if they are not identical.

- The option `-b `branch[[fromfile[rev]]``tofile[rev]]`` allows you to specify a `fromfile` file pattern and a `tofile` revision, or a `fromfile` revision and a `tofile` file pattern.
- RCS keywords within files are not expanded with `p4 diff2`.

## Usage notes

Can File Arguments Use Revision Specifier? | Can File Arguments Use Revision Range? | Minimal Access Level Required
--- | --- | ---
Yes | No | list protection, read permission

## Examples

`p4 diff2 //repo/main/src/...@00662f4 //repo/main/src/...@refs/heads/bugfix`

where `@00662f4` represents the commit SHA-1 and `refs/heads/bugfix` represents the branch. The output might show differences between the files currently in the branch and files in the commit:

Copy

    ==== //repo/main/src/chat.c#1e7637e (text) - //repo/main/src/chat.c#1e7637e (text) ==== identical
    ==== //repo/main/src/db.c#6950848 (text) - //repo/main/src/db.c#2ab62af (text) ==== content
    2,3d1
    < Additional database code.
    < Add Btree code
    ==== //repo/main/src/main.c#184e90a (text) - //repo/main/src/main.c#5a8f6ff (text) ==== content
    3d2
    < Enable additional database code.

where #number represents the blob SHA-1 of a file associated with the commit SHA-1.

Your search for returned results