10 Diffs

There are two methods of producing file diffs in Perforce, either against local changes that have not been submitted yet, or between two trees (or within a branch) in the depot. These are done with different commands, diff and diff2:

p4 diff

This generates a diff of the local changes to files in the edit state. The -du and -dc flags can be used to create unified or context diffs, respectively, or the P4DIFF environment variable can be set to a local diff command to be used instead. It is a very good idea to use this command to review your changes before submitting them.

p4 diff2

This creates a diff between arbitrary files in the depot, or between files specified in a branch spec. The diff operation takes place on the server, so P4DIFF variable has no effect, though the -du and -dc flags do work. The two forms of this command are:

% p4 diff2 -b branchname

and

% p4 diff2 //depot/path1 //depot/path2

In all cases the diff will be written to the standard output. Unfortunately, Perforce produces a diff format that is slightly incompatible with the traditional Unix diff and patch tools. Using the P4DIFF variable to point to the real diff(1) tool can help this, but only for the p4 diff command. The output of diff2 command must be post-processed to be useful (the -u flag of diff2 will produce unified diffs that are somewhat compatible, but it does not include files that have been added or deleted). There is a post-processing script at: http://people.freebsd.org/~scottl/awkdiff.

This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.

For questions about FreeBSD, read the documentation before contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.