Comparing and Merging

SlickEdit® Core provides several ways to compare and merge files:

DIFFzilla

DIFFzilla® provides powerful differencing capabilities that let you compare files or directories and view the differences side-by-side. You can make edits, merge changes, and save modified files easily within the results windows. As edits are made, the diff view is updated as you type, so you don't have to re-run the comparison. And, switching from a directory comparison to an individual file difference is as simple as a mouse click.

Dynamic Difference Editing

Unlike most diff tools, DIFFzilla® allows you to edit your code while viewing differences. Undo, copy/paste, Syntax Expansion/indenting, SmartPaste®, Auto List Members, Auto Parameter Info and many emulation key mappings work when editing in DIFFzilla. When you type or make any edit, lines are re-diffed (compared again) so that you can view the new intra-line differences easily.

Source Diff

With Source Diff, DIFFzilla ignores whitespace and carriage returns when comparing two files. This allows you to see real differences in the code while ignoring differences in formatting. For example, look at the two code samples, below. They are identical, except for the brace style used. Most diff tools will tell you that they are different. Source Diff will tell you that these two are the same.

        Rectangle::Rectangle() {
        }
      
        Rectangle::Rectangle()
        {
        }
      

Using Source Diff, DIFFzilla presents the Path 2 file with it's formatting adjusted to match that of the Path 1 file. We insert stream markers to indicate whitespace that was added or removed.We make a copy of the file specified in Path 2, so no actual changes to the file are made.

In this screen shot, you can see a blue squiggle (highlighted in the red circle) that indicates where the formatting was adjusted. The file on the right is actually formatted with the braces on separate lines, but Source Diff adjusts them to match the formatting of the file on the left. These adjustments are skipped by Next Diff and Prev Diff, allowing you to focus on meaningful differences, like the extra definition in the file on the right.

Using DIFFzilla

The following sections describe how to use DIFFzilla and the differencing features in SlickEdit Core. For more details on the specific options available on the DIFFzilla dialog (Tools → File Difference or diff command), see DIFFzilla® Dialog.

Comparing Two Files

To diff two source files, complete the following steps:

  1. From the main menu click Tools → File Difference, or use the diff command. The DIFFzilla® dialog appears, as pictured below.

  2. Under Diff Type, select the Compare Two Files option.

  3. Enter the name of the first file to compare in the Path 1 text box. Enter the name of the second file in the Path 2 text box. If the file names only differ by path, you only need to specify the path for Path 2.

  4. Click OK.

Alternatively, you can use DIFFzilla to diff files from several Eclipse views, including the Package Explorer and the Project Explorer:

  1. From the Eclipse view, select the two files that you want to diff and right-click.

  2. From the Compare With submenu, click Each Other (DIFFzilla).

Comparing Two Directories

You can difference two source trees to determine what files have been added or removed and generate a list of file names. When the source tree difference is complete, click Save to generate a list file. To diff two source trees, complete the following steps.

  1. From the main menu, click Tools → File Difference, or use the diff command.

  2. Mark the Recurse into subdirectories check box to compare subdirectories.

  3. Enter the two directories in the Path 1 and Path 2 text boxes.

  4. Fill in the Filespecs text box with the files that you want processed.

  5. Click OK. The Multi-File Diff Output dialog is displayed.

If a file exists in one tree but not the other, a plus sign (+) is displayed in the one tree and a minus sign (-) in the other. You can customize the files to view with the context menu. To display the context menu, right-click in the left or right tree. If you move the mouse over the Plus or Minus bitmap next to the item in the tool tree, a tool tip is displayed indicating what the bitmap means.

For descriptions of the buttons on the Multi-File Diff Output dialog, see Multi-File Diff Output Dialog.

Comparing Symbols

DIFFzilla® provides the ability to diff (compare) a selected range of lines from two files or the same file. This is very useful for comparing a piece of code that has been moved into a different part of a different file.

Note

You can only use the interactive dialog output style when diffing a selected range of lines. Therefore, the option Instead of an interactive dialog, output one buffer with the differences labeled, on the DIFFzilla dialog Options tab, will have no effect.

To compare symbols, select the Symbols option under Diff Type on the DIFFzilla dialog, and all symbols from Path 1 will be diffed against all symbols from Path 2. If Multi-File is selected as the Diff Type, it always allows you to diff all symbols. Be sure to be careful when diffing all symbols. Some symbol blocks are not yet picked up correctly. For example, for C++, C#, and Java, variable initializations are not yet handled correctly, as shown in the code below:

struct MYSTRUCT {
          int x;
          int y;
      };
      MYSTRUCT VariableDefinition= { // symbol definition stops here
         0,1
      };     // really should end here

To diff a selected range of lines from two source files, complete the following steps:

  1. From the main menu, click Tools → File Difference.

  2. Select the Compare Two Files diff type.

  3. Enter the first file in the Path 1 text box.

  4. Select Compare symbols: all, in the second drop-down list.

  5. Enter the second file in the Path 2 text box.

Comparing Parts of Files

To diff a selected range of lines from two source files or from a single source file, complete the following steps:

Tip

You can compare line ranges from within a single file. This can be useful when working with XML or data files.

  1. From the main menu, click Tools → File Difference.

  2. Select the Compare Two Files diff type.

  3. Type the name of the first file in the Path 1 text box.

  4. Select Compare lines: range, in the second drop-down list. The Select line range dialog will be displayed. Specify the line range using a selection or by enter the start and end line numbers.

  5. Repeat the previous steps for the second file using Path 2.

  6. Click OK to begin the comparison.

Generating File Lists

DIFFzilla® can be used to find only the files that have been changed, and can generate file lists. The Save button in the Multi-File Diff Output dialog can create a list of files that includes different files, matching files, and files that do not exist in the other tree. Use the DIFFzilla dialog box to compare the new source tree with the original source tree.

  1. From the main menu, click Tools → File Difference, or use the diff command.

  2. On the Files tab, select Multi-File.

  3. Enter the first file in the Path 1 text box.

  4. Enter the second file in the Path 2 text box. If the file names only differ by path, you only need to specify the path for Path 2.

  5. Click OK. The Multi-File Diff Output Dialog box opens.

  6. Click Save. The Save Multi-File Output dialog box opens.

  7. Select Save Path 1 Filelist, Include different files, and Include files not in Path2. All other check boxes should be clear.

  8. Click OK and select an output file for the list. The file you save will have the .lst extension appended to the output file name.

  9. Zip the files if you want.

Automatic Directory Mapping

The DIFFzilla® dialog box automatically updates the Path 2 text box with a directory, based on file paths that you previously typed in this field. For example, if you previously typed f:\slick12\bitmaps\ into the Path 1 text box and \\server\user\slick12\bitmaps\ into the Path 2 text box, then f:\slick12\ is mapped to \\server\user\slick12\. The next time that you type f:\slick12\macros\ in the Path 1 text box, \\server\user\slick12\macros\ is automatically entered into the Path 2 text box.

To turn this option off, complete the following steps.

  1. From the main menu, click Tools → File Difference, or use the diff command.

  2. Select the Options tab.

  3. Click Dialog Setup.

  4. Clear the Automatic directory mapping check box.

3-Way Merge

The 3-Way Merge editing feature can be used after two people make a local copy of the same source file, and each makes modifications to their local copy. The 3-Way Merge takes both sets of changes and creates a new source file. If there are any differences, a dialog box is displayed that lets you select the changes that you want in the output file. The output file can be viewed side-by-side or interleaved.

Performing a Three-Way Merge

To perform a three-way merge, complete the following steps:

  1. From the main menu, click Tools → File Merge (or use the merge command). The 3-Way Merge Setup dialog is displayed.

  2. In the Filename text box, enter the baseline (original) file name. Click the Ellipses button to the right of the text box to select files. Click the Bbutton to select from the open buffers.

  3. Enter the other names of the files to be merged in the Revision 1 and 2 text boxes.

  4. In the Output file Filename text box, enter the name of the output file, or click the Ellipses button to select from an existing file.

  5. Select any Merge style or Output style that you want.

  6. Click OK. The following dialog box is displayed with the results of the 3-Way Merge:

3-Way Merge Settings

For descriptions of the options on the 3-Way Merge Setup dialog, see Tools Dialogs and Views.