Compare File Revisions: diff
Use diff to display differences between two revisions of a file. The command can be applied to more than one file. If you do not specify any revisions using -vn, -vd, -vl, or -vp, the working copy of each specified file is compared to the tip revision in the repository (or vault) for this file. IIf you specify a single revision, the tip revision of each specified file is compared to that revision. If you specify two revisions, those two revisions of each specified file are compared.
When comparing text files, the differences can be displayed. When comparing binary files, output results indicate whether the revisions of the file are the same or different.
Syntax
The syntax for this command is:
stcmd{Ex} diff [ -p "projectSpecifier" [-epwdfile "filePath"] [-cmp] [-csf] [-dwf] [-encrypt encryptionType] ][-cfgl "labelName"| -cfgp "stateName" | -cfgd "asOfDate"] [-is] [-rp "folderPath" | -fp "folderPath"] [-filter "fileStatus"] [-eol [on | off | cr| lf| crlf]] [-w | -Bpvcs | -b] [-I] [-m "maskSet"] [-t number] [-c number] [-n] [-nd] [-vl "labelName" | -vd "asOfDate" | -vn revisionNumber] [-pattern "date-pattern"] | -vp promotionStateName[files...]
Parameters
For information about the command parameters, refer to Operation Parameters.
In addition:
Parameter |
Description |
---|---|
-w |
Ignores all whitespace (tabs and spaces) when comparing two lines in text files. For example, the following lines would be equivalent: "a = ( b + 2);" "a=(b+2);" The-w, -Bpvcs, and -b options are mutually exclusive. |
-Bpvcs |
When comparing two lines of text files, ignores leading and trailing whitespace. For example, the following lines are equivalent because there is only one space between "hi" and "mom": " hi mom " " hi mom" but the next line is not equivalent: "hi mom" |
-b |
When comparing two lines of text files, ignores trailing whitespace and treats all other strings of whitespace as equal in length. For example, the following lines are equivalent: " hi mom " " hi mom" |
-I | Ignores the case of letters when comparing two text files. For example, "A" is equivalent to "a". |
-m |
When comparing two text files, ignores the characters in certain columns as specified by one or more masks. Each mask has the following syntax: "columnNumber-columnNumber[(numeric)]" For example, "1-6" ignores the characters in the first six columns of each line, and "1-6 (numeric)" ignores the first six columns of each line if the character in column 1 is a digit in both files. You can use a series of masks, but they must be separated by commas. The syntax is: "mask[,mask]..." |
-t | Specifies the number of spaces to use for each tab stop when displaying the file differences for text files. The default is four. Use -t 0 to suppress tab conversion. |
-c | Specifies the number of unchanged lines to display before and after a difference is found in text files. Without this option, all lines of the files are displayed. For example, -c 2 places two unchanged lines before and after each line or set of lines that has changed. |
-n | Suppresses the display of line numbers in the two text files. |
-nd | Suppresses the display of differences in two text files. Comparisons of binary files do not display differences. |
-dwf |
Available in versions: 17.1 and higher Diff Working Folders. Compare working copy of the file. Example: The example compares the working copy of “text.txt” to revision 5 of that file. |
Example
The following example uses diff to compare the Beta1 and Beta2 revisions of each of the .cpp files in the folder SourceCode, a child of the root folder StarDraw (in the StarDraw view of the StarDraw project). It ignores all white space.
Use the -p with diff or the stateful set command to set the context of the project/view/parent folder.
stcmd diff "SourceCode" -w -vl "Beta1" -vl "Beta2" "*.cpp"
Note that diff compares versions of files at differing specified revisions of the view, which allows you flexibility in determining how to specify the revisions of interest. A few examples are listed below.
Compare .cpp files in the view between labels Beta1 and Beta2:
stcmd diff "SourceCode" -w -vl "Beta1" -vl "Beta2" "*.cpp"
Compare .java files in the view between dates March 01 1997 to Jan 01 2013:
stcmd diff "SourceCode" -w -pattern MM/DD/yyyy -vd 03/01/1997 -vd 01/01/2013 "*.java"
Compare .java files in the view between date March 01 1997 and the label Beta2:
stcmd diff "SourceCode" -w -pattern MM/DD/yyyy -vd 03/01/1997 -vl "Beta2" "*.java"
Compare .cs files in the view between date December 31 2013 and the tip:
stcmd diff "SourceCode" -w -pattern MM/DD/yyyy -vd 12/31/2013 "*.cs"
Also, the best use of -vd is in conjunction with the -pattern option. The -pattern specifications is part of the java SimpleDateFormat and permits the engine to precisely determine what one has in mind when specifying a date without attempting to guess at intent.