Merging Files

Merge provides a number of tools to enable you to quickly merge text files together to produce a file that can be saved. This article describes the merging process in detail.

In-place editing

As well as the merging operations described below, you can always fine-tune by editing text in-place. For more information, see Editing Files.

Merging buttons

There is a small merging button at the top-right corner of each block of changed lines.

  • Click a merging button to make the lines replace the corresponding block of lines in the other file.
  • To insert the block of lines after the lines in the other file, hold Ctrl when you click.
  • To insert the block of lines before the lines in the other file, hold Shift when you click.
  • To delete a block of lines, hold Ctrl+Shift and click the button.

The merging button icon changes to indicate its operation when you press Ctrl  , Shift  , or Ctrl+Shift  .

Information By default, merging buttons to replace, append and prepend a block are not displayed if the destination file is read-only. Likewise, delete buttons are not shown in read-only files. This behaviour can be overridden by enabling the Allow editing of read-only files option.

Information When using merging buttons to copy lines from one file to another, or when inserting text into a file in any other way, Merge changes the line endings (CR and/or LF characters) in the lines copied to the predominant line endings found in the destination file. If this is not the behaviour you desire, you can specify different line endings when you save a file, as described in the topic Saving Files.

You can also use keyboard shortcuts to replace, insert and delete blocks of lines:

  • Ctrl+Q replaces the adjacent change on the left with the contents of the current change.
  • Ctrl+W replaces the adjacent change on the right with the contents of the current change.
  • Shift+Ctrl+W appends the current change after the adjacent change.
  • Ctrl+Alt+E deletes the current change.

For a full list of keyboard shortcuts, see File Comparison Keyboard Shortcuts.

Merging multiple changes in one go

Multiple merging buttons can be selected. Clicking any selected merging button applies its action to all the blocks of changed lines that have selected buttons.

To select several merging buttons, hold Alt and then click-and-drag to draw a selection box around the buttons. Additional merging buttons can be added to the selection by holding Alt and click-dragging further boxes. Press Ctrl+Shift+A to select all the merging buttons.

Fine-grained merging

The merging buttons and the commands in their context menus may not enable you to perform the exact merge you desire. Use drag and drop text editing or the Copy and Paste commands to copy just part of a block of changed lines or to insert lines at an arbitrary location in another file.

Complex change blocks can also be broken into smaller blocks of inserted, removed, and changed text using the Intelligently split blocks of changed text based on matched line pairs option on the text comparison Line Pairing options page. This can make it easier to propagate individual changes from one file to another.

When merging changes from one file into another, you may need to correct the indentation of the merged changes. Highlight the lines you want to adjust and press Ctrl+I or Ctrl+U keys to indent or un-indent the block of highlighted lines. If the Tab key option is set, use you also use Tab and Shift++Tab to indent and un-indent the highlighted lines, respectively.

Marking of changes

Every change that is made to a file is flagged with an edit marker . If lines are introduced into a file, the edit marker is an arrow ( or ) indicating the file from which the lines were copied. If lines are removed from the file, a delete marker is placed on the line after the position at which the lines were removed.

Each edit marker has an associated tool tip that explains why the edit was made. Hold the pointer over the marker for a few seconds to see the tool tip. Conflict markers arising from a three-way automatic merge also have tool tips to explain the reason for the conflict.

You can navigate between edit markers using the Previous edit and Next edit buttons or the commands in the Markers section of the Edit menu.

Replacing the contents of one pane with another

If you want to replace one pane with the contents of another, use the replace commands located in the Replace content ribbon menu.

Automatic merging

Merge also supports automatic merging of two modified files into a common ancestor file. For more information about this type of merging, please see the Three-Way File Comparison and Merging and Automatic File Merging topics.