This documentation was written to describe the 1.7.x series of Apache™ Subversion®. If you are running a different version of Subversion, you are strongly encouraged to visit http://www.svnbook.com/ and instead consult the version of this documentation appropriate for your version of Subversion.

Name

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

Synopsis

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

svn merge --reintegrate 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 this 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.

  • Sync and Cherrypick Merges

    The first form, when used without either the -c or -r options, is called a sync merge and -r 1:REV is implied. This variant is used to merge all eligible changes to a branch from its immediate ancestor branch, see the section called “Keeping a Branch in Sync”.

    When the first form is used with the -c or -r options, this is called a cherrypick merge and is used to merge an explicitly defined set of changes from one branch to another, see the section called “Cherrypicking”

    [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).

    In both variants of the first form, SOURCE in revision REV is compared as it existed between revisions N and M for each revision range provided.

  • Reintegrate Merges

    The second form is called a reintegrate merge and is used to bring changes from a feature branch (SOURCE) back into the feature branch's immediate ancestor branch (TARGET_WCPATH).

    [Tip] Tip

    Reintegrate merges support only this specialized use case and as such have a number of special requirements and limitations that the other two merge forms do not posses. See the section called “Keeping a Branch in Sync”, the section called “Reintegrating a Branch”, the section called “Keeping a Reintegrated Branch Alive”, and the section called “Feature Branches”.

  • 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 using the first two forms. 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.

[Tip] Tip

Merge Tracking can be disabled by using the --ignore-ancestry option.

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.

Options

Examples

Merge a branch back into the trunk (assuming that you have an up-to-date working copy of the trunk):

$ svn merge --reintegrate \
            http://svn.example.com/repos/calc/branches/my-calc-branch
--- Merging differences between repository URLs into '.':
U    button.c
U    integer.c
U    Makefile
 U   .
--- Recording mergeinfo for merge between repository URLs into '.':
 U   .

$ # build, test, verify, ...

$ svn commit -m "Merge my-calc-branch back into trunk!"
Sending        .
Sending        button.c
Sending        integer.c
Sending        Makefile
Transmitting file data ..
Committed revision 391.

To merge changes to a single file:

$ svn merge -c 31 ^/trunk/thhgttg.txt thhgttg.txt 
--- Merging r31 into 'thhgttg.txt':
U    thhgttg.txt
--- Recording mergeinfo for merge of r31 into 'thhgttg.txt':
 U   thhgttg.txt