Merging Files Between Codelines

To create a new codeline (referred to as branching) or propagate a bug fix or new feature from one codeline to another, you integrate the required files to the target codeline. To integrate files, you open them for integration, specifying source and target, then submit the changelist containing the open files.

P4V performs three types of integration:

  • Branching, which creates a new codeline or branch.

    For more information, see Creating Branches.

  • Merging, which propagates change from one existing codeline to another and prompts you to resolve any conflicts between the codelines

  • Copying, which is reserved for propagating a straightforward duplicate of the files in one codeline to another.

    For more information about copying, see Merging Down and Copying Up between Streams.

If you are merging changes into an existing codeline, you are required to resolve the files to ensure that you do not overwrite other users' changes and to preserve the file's revision history. Typical steps for propagating changes from one codeline to another are as follows:

  1. Open files for merge.

  2. Submit the changelist.

    If there are conflicts, Perforce notifies you and schedules the files for resolve.

  3. Resolve the files, deciding how changed files are to be submitted.

  4. Submit the changelist containing the resolved files.

When you open files for merge, you can specify the mapping of source to target using either a file specification or a branch mapping.

  • File specification: you specify the source and target files when you open files for merging.

  • Branch mapping: you select a branch mapping when you open files for merging. Branch mappings enable you to predefine source and target codelines. For details about branch mappings, see the P4 User's Guide.

Note

The workflow for propagating change between streams ("merge up, copy down") is simple and specific. For more information, see Merging Down and Copying Up between Streams.

Note on terminology

In the Perforce Command-line Client, the term integrate is used not only to encompass all three integration types (branch, merge, copy), but is also used synonymously with the P4V term, merge. Within P4V, merge can refer both to merging files from one codeline to another and to merging conflicts between files (the function performed by P4Merge).

Open files for merge

To open files for merging:

  1. Select the source files and folders, then context-click and choose Merge/Integrate...

    The Merge/Integrate dialog is displayed.

  2. For Merge method, choose Specify source and target files.

    The source files that you selected in step 1 are listed in the Source files/folders field.

  3. Specify the target files and folders by typing or browsing to the destination.

  4. To specify additional merge options, click the Options disclosure triangle.

    The Options panel appears.

    Specify integration options as follows:

    Resolve and Submit Options: These options enable you to specify whether files are submitted manually or automatically, and to configure how conflicts are resolved.

    Filter Options: Filtering enables you to choose a subset of the revisions that are queued for merging. For more information, see Searching and Filtering.

    Advanced Options: These options enable you to refine the results of the merge as follows:

    • Do not copy newly branched target files to workspace (-v): Create a branch in the depot without retrieving the corresponding files from the depot to your workspace.

    • Enable baseless merges (-i): Perform the integration even if source and target share no common ancestor, using the most-recently-added revision of the source file as the base.

    • Try to integrate changes when source deleted and re-added (-Di): If the target file has been deleted and the source file changed, this option re-branches the source file on top of the target file. If the source file has been deleted and the target file has changed, this option deletes the target file. By default, outstanding edits cannot be integrated with a deleted file.

    • Force integration on all revisions, disregarding integration history (-f): Integrate all revisions of source and target files, including revisions that have already been integrated. Typically used with a specified revision range.

    • Do not get latest revision of selected files (-h): Use the workspace revision of the target file. By default, the head revision of the target file is automatically retrieved into the workspace before integrating.

    • Disregard indirect integration history (-1): Restrict selection of the base file revision to direct (parent-to-child or child-to-parent) integration history.

    • Propagate source filetypes to target files (-t): Assign the target file the same file type as the source file (when integrating to existing target files).

    • Schedule 'branch resolves' (-Rb): Schedules a branch resolve, instead of branching new target files automatically.

    • Schedule 'delete resolves' (-Rd): Schedules a delete resolve, instead of deleting target files automatically.

    • Skip 'cherry-picked' selected revisions (-Rs): Skips cherry-picked revisions that have already been integrated. This option can improve merge results, but can also require multiple resolves per file.

    • Check for opened files and warn prior to merging: Detect whether any of the selected files are open for other actions.

    Note

    P4V uses different Perforce commands to apply these integrate flags, depending on the integration method:

    • Stream-to stream method: p4 merge

    • Branch mapping and files and folders methods: p4 integrate

    For more information about these Perforce commands and flags, see the Perforce Command Reference.

  5. To perform the merge, click Merge.

    The specified files are opened for merge using any options you configured.

  6. Resolve and submit the files.

Click Set Defaults to open the Merge-Integrate preferences page, where you can set default behaviors for the Merge/Integrate dialog.