This text is a work in progress—highly subject to change—and may not accurately describe any released version of the Apache™ Subversion® software. Bookmarking or otherwise referring others to this page is probably not such a smart idea. Please visit http://www.svnbook.com/ for stable versions of this book.

Name

svn merge — Apply the differences between two sources to a working copy path.

Synopsis

svn merge SOURCE[@REV] [TARGET_WCPATH]

svn merge [-c M[,N...] | -r N:M ...] SOURCE[@REV] [TARGET_WCPATH]

svn merge SOURCE1[@N] SOURCE2[@M] [TARGET_WCPATH]

Description

In all three forms TARGET_WCPATH is the working copy path that will receive the differences. If TARGET_WCPATH is omitted, the changes are applied to the current working directory, unless the sources have identical basenames that match a file within the current working directory. In that case, the differences will be applied to that file.

In the first two forms, SOURCE can be either a URL or a working copy path (in which case its corresponding URL is used). If the peg revision REV is not specified, then HEAD is assumed. In the third form the same rules apply for SOURCE1, SOURCE2, M, and N with the only difference being that if either source is a working copy path, then the peg revisions must be explicitly stated.

  • Automatic Merges

    The first form is called an automatic merge and is used to perform sync and reintegrate merges. Sync merges merge eligible changes to a branch (TARGET_WCPATH) from the branch's ancestor branch (SOURCE). Eligible changes are defined as those that were not previously merged from SOURCE to TARGET_WCPATH. See the section called “Keeping a Branch in Sync”. Reintegrate merges merge changes from a feature branch (SOURCE) back into the feature branch's ancestor branch (TARGET_WCPATH), see the section called “Reintegrating a Branch” and the section called “Feature Branches”.

  • Cherrypick Merges

    The second form is called a cherry-pick merge and is used to merge an explicitly defined set of changes from one branch to another. SOURCE in revision REV is compared as it existed between revisions N and M for each revision range provided. See the section called “Cherrypicking” for more information.

    [Tip] Tip

    Multiple -c and/or -r instances may be specified, and mixing of forward and reverse ranges is allowed— the ranges are internally compacted to their minimum representation before merging begins (which may result in a no-op merge or conflicts that cause the merge to stop before merging all of the requested revisions).

  • 2-URL Merges

    In the third form, called a 2-URL Merge, the difference between SOURCE1 at revision N and SOURCE2 at revision M is generated and applied to TARGET_WCPATH. The revisions default to HEAD if omitted.

If Merge Tracking is active, then Subversion will internally track metadata (i.e. the svn:mergeinfo property) about merge operations when the two merge sources are ancestrally related—if the first source is an ancestor of the second or vice versa—this is guaranteed to be the case when performing automatic merges. Subversion will also take preexisting merge metadata on the working copy target into account when determining what revisions to merge and in an effort to avoid repeat merges and needless conflicts it may only merge a subset of the requested ranges.

Unlike svn diff, the merge command takes the ancestry of a file into consideration when performing a merge operation. This is very important when you're merging changes from one branch into another and you've renamed a file on one branch but not the other.

[Tip] Tip

The --ignore-ancestry option will cause Merge Tracking to be disabled and makes merge act like svn diff, ignoring the ancestry of files when merging.

Options

Examples

Reintegrate a branch back into the trunk—assuming that you have an up-to-date working copy of the trunk (the --verbose option prints additional information regarding what the merge is doing prior to actually applying any diff; useful in very large which might take a significant amount of time to complete):

$ svn merge ^/branches/feature-branch-calc-enhancements trunk --verbose
checking branch relationship...
calculating automatic merge...
merging...
--- Merging r12 through r37 into 'trunk':
U    trunk/calc/brush.c
--- Recording mergeinfo for merge of r12 through r37 into 'trunk':
 U   trunk

$ # build, test, verify, ...

$ svn commit trunk -m "Reintegrate the calc enhancements back to trunk!"
Sending        trunk
Sending        trunk/calc/brush.c
Transmitting file data .
Committed revision 38.

Cherry-pick merge a single change to a file:

$ svn merge ^/trunk/calc/brush.c branches/1.x/calc/brush.c -c38
--- Merging r38 into 'branches/1.x/calc/brush.c':
U    branches/1.x/calc/brush.c
--- Recording mergeinfo for merge of r38 into 'branches/1.x/calc/brush.c':
 G   branches/1.x/calc/brush.c

Merge the differences between two unrelated branches into a third branch:

$ svn merge ^/vendor-drop/vendor-1.0 ^/vendor-drop/vendor-1.1 \
            trunk --ignore-ancestry
--- Merging differences between repository URLs into 'trunk':
U    trunk/draw/draw.py