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

P4 CLI Documentation | 2026.1

# p4 diff

Diff utility for comparing workspace content to depot content. (For comparing two depot paths, see p4 diff2.) Also for stream spec comparison.

## Syntax

    p4 [g-opts] diff [-doptions] [-f -t -Od] [-m max] [-soptions] [file[rev] ...]
    p4 [g-opts] diff [-doptions] -As [streamname[@change]]

Syntax and naming conventions

## Description

p4 diff runs a diff program on your workstation that compares files in your workspace to revisions in the depot.

This command takes a file argument, which can contain a revision specifier.

- If a revision specifier is included, the file in the client workspace is diffed against the specified revision.
- If a revision specifier is not included, the client workspace file is compared against the revision currently being edited (usually the head revision).
- In either case, the client file must be open for `edit`, or the comparison must be against a revision other than the one to which the client file was last synced.

If the file argument includes wildcards, all open files that match the file pattern are diffed.

If no file argument is provided, all open files are diffed against their depot counterparts.

By default, your workstation runs the diff routine built into the P4 CLI command-line application. You can make your workstation run an external diff program by setting the `P4DIFF` environment variable to point to your external diff program.

### To diff stream specs

p4 [g-opts] diff [-doptions] -As [streamname[@change]] allows the user to diff a privately edited stream spec against another version of the same stream spec. To use this option, the user's client workspace must be associated with the given stream, and the stream spec must be privately opened for edit.

## Options for workspace content

Option | Description
--- | ---
`-d`options`` | Pass options to the underlying diff routine (see Usage notes for details).
`-f` | Force the diff (if no revision is specified, against the head revision), even when the client file is not open for `edit`.
`-m max` | Limit output to diffs (or status) of only the first `max` files, unless the `-s` option is used, in which case the `-m` option is ignored.
`-Od` | Limit output to only those files that differ.
`-s`options`` | Pass display options to the underlying diff routine (see Usage notes for details).
`-t` | Diff the revisions even if the files are not of type `text`.
`g-opts` | See Global options.

## Options for stream specs

Option | Description
--- | ---
`-d`options`` | Pass options to the underlying diff routine (see Usage notes for details).
`-As` | Allows two arbitrary stream specs to be diffed against each other. Can be used with a streamname, or with a streamname at a specific changelist number. Although this option requires the user have at least the list access to the stream path, it ignores any other entry in the protections table, including any minus sign (-) that would otherwise block the operation.
`g-opts` | See Global options.

## Usage notes

Can file arguments use revision specifier? | Can file arguments use revision range? | Minimal access level required
--- | --- | ---
Yes | No | `read` or list to use the -As option

- The `-d`options`` supported by `p4 diff` are:

  Option | Name
  --- | ---
  `-db` | ignore changes made within whitespace; this option implies `-dl`.
  `-dc[`num`]` | context output format, showing line number ranges and `num` lines of context around the changes.
  `-dl` | ignore line-ending (CR/LF) convention when finding diffs.
  `-dn` | RCS output format, showing additions and deletions made to the file and associated line ranges.
  `-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.
  `-dw` | ignore whitespace altogether; this option implies `-dl`.

- The `-s`options`` supported by `p4 diff` are:

  Option | Name
  --- | ---
  `-sa` | Show only the names of opened files that are different from the revision in the depot, or are missing.
  `-sb` | Show only the names of files opened for integrate that have been resolved, but that have been modified after being resolved.
  `-sd` | Show only the names of unopened files that are missing from the client workspace, but present in the depot.
  `-se` | Show only the names of unopened files in the client workspace that are different than the revision in the depot.
  `-sl `file ...`` | Every unopened `file` is compared with the depot, and listed with a status of `same`, `diff`, or `missing`. If you use the `-f` option together with the `-sl` option, files that are open for edit are also compared and their status is listed.
  `-sr` | Show only the names of opened files in the client workspace that are identical to the revision in the depot.

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

  `p4 diff -dub file`

  specifies a unified diff that ignores changes in whitespace.

- The header line of a unified diff produced with the `-du` option for use with `patch(1)` displays filenames in P4 Server syntax, not local syntax.
- If a revision is provided in the file specification, the `-s` options compare the file(s) regardless of whether they are opened in a changelist or the workspace has been synced to the specified revision.

## Examples for workspace content

`p4 diff file#5` | Compare the client workspace revision of file `file` to the fifth depot revision.
`p4 diff @2017/05/22` | Compare all open files in the client workspace to the revisions in the depot as of midnight on May 22, 2017.
`p4 diff -m 10 @2017/05/22` | Limit to the first 10 files the comparison all open files in the client workspace to the revisions in the depot as of midnight on May 22, 2017.
`p4 diff -du file` | Run the comparison on file `file`, displaying output in a format suitable for the `patch(1)` utility.
`p4 diff -sr | p4 -x - revert` | Revert all open, unchanged files. This differs from `p4 revert` `-a` (revert all unchanged files, where resolving a file, even if no changes are made, counts as a change), in that it reverts files whose workspace content matches the depot content, including resolved files that happen to be identical to those in the depot. The first command shows all open, unchanged files. The second command (running `p4 -x` and taking arguments, one per line, from standard input, abbreviated as “-”) reverts each file in that list. (This UNIX version of this command uses a pipe. Most operating systems have a similar way of performing these operations in series). For more information about the `-x` option to the P4 CLI, see Global options.

## Examples for stream specs

p4 diff -As p4 diff -As myStream p4 diff -As myStream@have | diff between the opened stream spec and the have version of the stream spec
p4 diff -As myStream@head | diff between the opened stream spec and the head version of the stream spec
p4 diff -As myStream@1 | diff between the opened stream spec and the version of the stream spec at change 1
p4 diff -As myStream@=1 | diff between the opened stream spec and the shelved version of the stream spec at change 1

## Related commands

To compare two depot revisions | `p4 diff2`
To view the entire contents of a file | `p4 print`

Your search for returned results