svn merge — Apply the differences between two sources to a working copy path.
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]
In all three forms
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
In the first two forms,
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
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
-roptions, is called a “sync” merge and
-r 1:REVis 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
-roptions, 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
-rinstances 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,
REVis compared as it existed between revisions
Mfor each revision range provided.
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 (
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”.
In the third form, called a “2-URL Merge”, the difference between
Mis generated and applied to
TARGET_WCPATH. The revisions default to
is active, then Subversion will internally track metadata
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.
can be disabled by using the
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.
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