Merging files

P4Merge enables you to compare two text files with a common base file to locate differences and to select the text that you want in the merged result file. The purple icon (file1) is associated with the file that another user edited (their file), and purple bands highlight text that is unique to that file. The green icon (file2) is associated with file that you edited (your file), and green bands highlight text that is in the second file but not the first file. The base file is indicated by the yellow icon (basefile), and yellow highlighting indicates text that is in the base file but not in the other files.

In the top half of the window, P4Merge displays the base file surrounded by the two changed versions of the revision being merged. In the bottom half of the window, P4Merge displays the merge results file, where you select or enter the text that you want to check in. Make your changes as described below, and be sure to save them before exiting P4Merge.

For information on merging files from within P4V, see Merging files and Resolving files in the Helix Core Visual Client (P4V) Guide.

To merge files:

  1. Go to File > New Merge or Diff.
  2. In the Choose Files dialog, on the Merge tab, specify the base file and the two files to be merged.

  3. Click OK.

    P4Merge shows each file in its own pane, with the base file in the middle. The bottom pane shows the merge results file, a consolidated, merged version of all files.

Navigate diffs

To move forward and back through individual differences, or to locate specific text or lines, click the toolbar buttons listed below.

Go to next diff

Go to next diff icon

Go to previous diff

Previous Diff icon

Find text

Find icon

Go to line number

Go to line icon

Merge text

To merge files, you can either choose text from one of the files or enter changes directly into the merge results file.

Choose Text Chunks

To choose the entire contents of a file, click the corresponding icon in the merge diagram, as shown below.

filediagram

To choose a single chunk of text from a set of diffs, click the corresponding button to the right of the chunk, as shown below.

The buttons indicate the origin of the text and the way it was changed, as follows:

basefile

Base file text

file1

Same in theirs and base.

file2

Same in yours and base.

theiradd

Text added to their file. Not in yours or base.

youradd

Text added to your file. Not in theirs or base.

theirdelete

Text deleted from their file.

yourdelete

Text deleted from your file.

sameyourstheirs

Same in yours and theirs, different from base.

addyourstheirs

Added to both yours and theirs.

deletedyourstheirs

Deleted from both yours and theirs.

Note that these are toggle buttons: click once to select the corresponding text, click again to deselect it.

If P4Merge encounters too many changes to display all the required buttons, it displays this button: expandme. Click it to view the details.

Note

If you are working with large text files, see the Support Knowledgebase article, Improving diff results when comparing files with more than 50,000 lines.

Tip

Syntax highlighting is available (starting with version 2020.2). Click the Show Syntax Highlighting button to toggle the feature on or off.

More than 300 languages supported languages are listed at https://kate-editor.org/syntax/.

Edit text

To edit the text in the merge result file, click on the text in the bottom pane and enter your changes. Manually edited text is displayed with a gray highlight, like the middle chunk in the following example: