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

P4 CLI Reference | 2025.1

# p4 diff2

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

You can specify the source and the target files on the command line or through a branch view.

Also compares two arbitrary stream specs with the -As option.

## Syntax

    p4 [g-opts] diff2 [-doptions] [-Od -q -t -u] file1[rev] file2[rev]
    p4 [g-opts] diff2 [-doptions] [-Od -q -t -u] -b branch [[fromfile[rev]] tofile[rev]]
    p4 [g-opts] diff2 [-doptions] [-Od -q -t -u] [-S stream] [-P parent] [[fromfile[rev]] tofile[rev]]
    p4 [g-opts] diff2 [-doptions] -As streamname1[@change1] streamname2[@change2]

Syntax conventions

## Description for depot content

p4 diff2 uses the Perforce service’s built-in diff routine to compare two file revisions from the depot. These revisions are usually two versions of the same file, but they can be revisions of entirely separate files. If no file revision is explicitly provided with the file argument, the head revision is used.

- If you specify no arguments, the current stream is diffed against its parent stream.
- If you specify a filename, it diffs that file in the current stream against its the same file in the parent stream.

The two files must both be text or unicode. You cannot compare a text file to a unicode file.

p4 diff2 ignores the client environment variable `P4DIFF` because it runs on the P4 Server.

You can specify file patterns as arguments in place of specific files, with or without revision specifiers. P4 Server performs diffs for each pair of files that match the given pattern. If you invoke `p4 diff2` with file patterns, escape the file patterns from the OS shell by using quotes or backslashes.

P4 Server presents the diffs in UNIX diff format, prepended with a header. The header is formatted as follows:

    ==== file1 (filetype1) - file2 (filetype2) ==== summary

The possible values and meanings of summary are:

- content: the file revisions' contents are different,
- types: the revisions' contents are identical, but the filetypes are different,
- identical: the revisions' contents and filetypes are identical.

If either file1 or file2 does not exist at the specified revision, the header displays the summary as `<none>`.

## Options for depot content

`-b `branch``from[rev]``to[rev]`` | Use a branch mapping to diff files in two branched codelines. The files that are compared can be limited by file patterns in either the `from` or `to` file specifications.
`-d`options`` | Runs the diff routine with one of a subset of the standard UNIX diff options. See Usage notes for a listing of these 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.
`-S `stream` [-P `parent`]` | Diff a stream with its parent. To diff the stream with a stream other than its configured parent, specify `-P`.
`-t` | Diff the file revisions even if the file(s) are not of type `text`.
`-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.
`g-opts` | See Global options.

## Description for stream specs

You can compare any two stream specs. For example, to diff between myStream at change 1 and yourStream at change 2:

p4 diff2 -As myStream@1 yourStream@2

and to diff between shelved stream specs:

p4 diff2 -As myStream@=1 yourStream@=2

## Options for stream specs

Allows the two specified stream specs to be diffed against each other.

`-d`options`` | Runs the diff routine with one of a subset of the standard UNIX diff options. See Usage notes for a listing of these options.
`-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. Limitation: 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 access necessary for both file revisions or list to use the -As option

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

  Option | Name
  --- | ---
  `-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 file1file2

  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`.

## Examples

`p4 diff2 -ds file#1 file` | Compare the first revision of file `file` to its head revision, and display a summary of what chunks were added to, deleted from, or changed within the file.
`p4 diff2 file@34 file@1998/12/04` | Diff the revision of `file` that was in the depot after changelist 34 was submitted against the revision in the depot at midnight on December 4, 1998.
`p4 diff2 //depot/rel1/... //depot/rel2/...#4` | Compare the head revisions of all files under `//depot/rel1` to the fourth revision of all files under `//depot/rel2`.
`p4 diff2 //depot/rel1/* //depot/rel2/...` | Not allowed. The wildcards in each file pattern must match.
`p4 diff2 -b branch2 //depot/rel2/...#2 @50` | Compare the second revision of the files in `//depot/rel2/...` to the files branched from it by branch mapping `branch2` at the revision they were at in changelist 50.

###

## Related commands

To compare a client workspace file to a depot file revision | `p4 diff`
To view the entire contents of a file | `p4 print`

Your search for returned results