Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

P4 CLI Documentation | 2025.2

# p4 merge

Merge 1. To create new files from existing files, preserving their history when branching. 2. To propagate changes from one set of files to another. 3. The process of combining the contents of two conflicting file revisions into a single file, typically using a merge tool, such as P4 Merge. one set of files (and/or the stream spec) into another.

## Syntax

    p4 [g-opts] merge [-c change] [-m max] [-K -n -Ob -q -F] [--from stream]
                      [toFileSpec[RevSpec]]
    p4 [g-opts] merge [-c change] [-m max] [-K -n -Ob -q] fromFileSpec[revSpec]
                      toFileSpec

For streams:

    p4 [g-opts] merge -S stream [-As | -Af]

Syntax and naming conventions

## Description

### Merging files

The `p4 merge` command is a simplified form of the `p4 integrate` command. `p4 merge` merges a set of changes from source to target files. The command outputs the scheduled resolves. This command is intended for use with streams and distributed version control, but is also usable for traditional P4 Server branches.

- Use `p4 resolve` to resolve all changes. Then use `p4 submit` to commit merged files to the depot. Unresolved files cannot be submitted.
- Use `p4 shelve` to shelve merged files or `p4 revert` to delete them.
- Use the `p4 integrated` and `p4 filelog` to display merge history.

In most cases, you can use the `p4 merge` and `p4 copy` commands to propagate changes between streams (or branches).

With no arguments, the target defaults to the stream associated with the current stream client, and the source defaults to the current stream parent.

You can specify a different source with `--from stream_name`, which is an alias for the `-P` option. You can specify the stream as a directory name relative to the current stream depot. For example, `--from main` instead of `--from //Ace/main`.

Using the client workspace as a staging area, `p4 merge` schedules all affected target files to be resolved per changes in the source. Target files outside of the current client view are not affected. Source files need not be within the client view.

Each file in the target is mapped to a file in the source. Mapping adjusts automatically for files that have been moved or renamed, as long as `p4 move` was used to move or rename the files. The scope of source and target files sets must include both old-named and new-named files for mappings to be adjusted. Moved source files can schedule moves to be resolved in target files. You can limit the revisions to be merged using the `revSpec` parameter.

An error message appears if the scope does not include both the old and the new files. For example, an error message appears if you run the merge on a single file that is either the move/add or move/delete of the move pair of actions.

### Merging streams

With streams, use `p4 merge` to keep a child stream up to date with a more stable parent stream. This ensures that when you promote changes back to the stable parent, you do not inadvertently overwrite any other changes that were checked into the parent. Files are opened in a pending changelist and scheduled for resolve as required. To update the parent stream, resolve and submit. By default, `p4 merge` merges changes into the current stream from its parent, or from another stream specified by the `--from` option. The source and target can also be specified on the command line as a pair of file paths. More complex merge mappings can be specified using branch specifications as with `p4 integrate`.

Use the `-F` option to force merging against a stream’s expected flow. You can also use this option to force the generation of a branch view based on a virtual stream. The mapping itself refers to the underlying real stream.

#### stream spec

p4 merge -S stream merges fields from the source stream spec into the target stream spec if those fields have been set to `propagate` with p4 streamspec.

The target stream spec becomes opened for edit, along with stream files. Use p4 merge -S stream -As to merge the stream spec only, and p4 merge -S stream -Af to merge files only.

#### The base

The `p4 integrate` and `p4 merge` commands select as the "base" revision the revision with the most edits in common with the source and the target.

## Options

Option | Description
--- | ---
`-c change` | Specifies an existing pending changelist in which the files are to be opened.
`-F` | Force merge operation. Perform the operation when the target stream is not configured to accept a merge from the source. To determine a stream’s expected flow of change, use `p4 istat`.
`--from stream` | Specifies a stream other than the parent stream to merge from. `-P` is an alias for `--from stream`
-S stream | Merges fields from the source stream spec into the target stream spec if those fields have been set to `propagate` with p4 streamspec. The target stream spec becomes opened for edit, along with stream files. To merge the stream spec only, use p4 merge -S stream -As To merge files only, use p4 merge -S stream -Af
`-K` | Suppress keyword expansion when updating +k type files on the client. See File type modifiers.
`-m max` | Limits the number of files merged. This option is useful for scripts that integrate large number of files. It enables them to batch the integrations and minimize the locking-related impact to other users of the shared versioning service.
`-n` | Preview the merge.
`-Ob` | The `-Ob` option displays the base revision for the merge (if any) along with each scheduled resolve.
`-q` | Quiet mode, which suppresses normal output messages about the list of files being integrated, copied, or merged. Messages regarding errors or exceptional conditions are displayed.
`-v` | Performs a "virtual" integration that does not modify client workspace files unless target files need to be resolved. After submitting a "virtual integration", p4 sync can be used to update the workspace.
`g-opts` | See Global options.

## Usage notes

Can File Arguments Use Revision Specifier? | Can File Arguments Use Revision Range? | Minimal Access Level Required
--- | --- | ---
Yes | Yes | `open`

## Examples

### Branches

`p4 merge` //mySourceBranch/... //myTargetBranch/... `p4 resolve` `p4 submit -d "Merge from source branch to target branch"` | Merge from the specified source branch to the specified target branch.

### Streams

`p4 merge` `p4 resolve` `p4 submit -d "Merge latest changes from parent stream"` | Merge into the current stream from its parent.
`p4 merge` --from `//Ace/rel1` `p4 resolve` `p4 submit -d "Merge from release"` | Merge into the current stream from the `//Ace/rel1` stream.
`p4 merge @100,104` `p4 resolve` `p4 submit -d "Merge five changes from parent"` | Merge changes `100` through `104` from the parent stream into the current stream.

## Related commands

Promote changes to more stable neighbor stream | `p4 copy`
Propagate changes | `p4 integrate`
Resolve file conflicts | `p4 resolve`

Your search for returned results