Command-Line Reference

Merge provides several command-line tools that enable you to launch Merge from a variety of applications. See Integrating with Source Control, Configuration Management, and Other Applications for application-specific instructions. The AppleScript API enables even greater control over Merge.

Compare command-line utility

The recommended way to use Merge from the command-line is to use the compare command-line utility. This program uses the Merge AppleScript API to launch file and folder comparisons within a new or existing instance of Merge.

Before using compare, ensure that the command-line utilities have been installed as described in the Installing the Merge command-line utilities section of the How to Install topic.

Usage

compare [-h] [-wait | -nowait]
    [-aN] [-swap] [-max]
    [-titleN:"<NthFileOrFolderTitle>" …] [-2 | -3]
    {fileArguments | folderArguments}

fileArguments for a file comparison are:

    [-readonly | -readonlyN …] [-merge [-testconflicts]]
    <firstFile> [<secondFile>] [<thirdFile>] [<mergedOutputFile>]

folderArguments for a folder comparison are:

    <firstFolder> [<secondFolder>] [<thirdFolder>]

General arguments

File comparison arguments

For two-way comparisons (-2), the files <firstFile> and <secondFile> (if present) are compared. If just one file argument is specified, a comparison is opened with only a single comparison panel populated.

For three-way comparisons (-3), the files <firstFile>, <secondFile>, and <thirdFile> are compared. Note that three-way comparisons require the Professional Edition of Merge.

An optional extra file argument, <mergedOutputFile>, can be specified for both two and three-way file comparisons. If present, this additional argument sets the default save filename if you save changes to any of the files in the file comparison. For example, <mergedOutputFile> is written if you save a file using the toolbar Save button. See Saving Files for further information.

When merging three files, it is easiest to merge changes from the left and right files into the middle one. For this reason, the common ancestor or base file (if any) should be displayed in the middle panel. The common ancestor file can be specified with the -aN command-line option if it is not possible to order the file arguments appropriately so that <secondFile> is the common ancestor. For further information about three-way comparison and merging, please see Three-Way File Comparisons and Automatic File Merging.

Folder comparison arguments

For two-way comparisons (-2), the folders <firstFolder> and <secondFolder> (if present) are compared. If just one folder argument is specified, a comparison is opened with only a single comparison panel populated.

For three-way comparisons (-3), the folders <firstFolder>, <secondFolder>, and <thirdFolder> are compared. Note that three-way comparisons require the Professional Edition of Merge.

When merging three folders, it is easiest to merge changes from the left and right folders into the middle one. For this reason, the common ancestor or base folder (if any) should be displayed in the middle panel. The common ancestor folder can be specified with the -aN command-line option if it is not possible to order the folder arguments appropriately so that <secondFolder> is the common ancestor. For further information about three-way folder comparison and merging, please see Three-Way Folder Comparisons and Automatic Folder Merging.

Examples

1.

compare file1.txt file2.txt

Opens a file comparison window comparing the two specified files.

2.

compare -wait file1.txt file2.txt

Opens a file comparison window comparing the two specified files. Compare will not exit until the user closes the file comparison window.

3.

compare -wait file1.txt file2.txt /tmp/merged.txt

Opens a file comparison window comparing the first two specified files. If the user attempts to save changes to either of the two files, /tmp/merged.txt will be used as the default save file name. Compare will not exit until the user closes the file comparison window.

4.

compare -wait -a1 -3 /tmp/file1.txt /tmp/file2.txt /tmp/file3.txt

Opens a file comparison window comparing the three specified files. Compare will not exit until the user closes the file comparison window. The first file specified is treated as the common ancestor of the other two and is therefore displayed in the middle file panel.

5.

compare -wait -a3 -3 -title1:"Djn’s Revision" -title2:"Jrs’s Revision" -title3:"Common Ancestor" /tmp/file1.txt /tmp/file2.txt /tmp/file3.txt /tmp/merged.txt

Opens a file comparison window comparing the first three specified files. If the user attempts to save changes to either of the three files, /tmp/merged.txt will be used as the default save file name. Compare will not exit until the user closes the file comparison window. The third file specified is treated as the common ancestor of the other two and is therefore displayed in the middle file panel. The file panels are given meaningful names.