127
votes

I'm facing a peculiar problem with SVN merge. I want to merge from a dev branch to trunk. We have multiple dev branches cut off the trunk at the same time.

I'm merging one of those branches to trunk with this command:

svn merge trunk branch_1

I see changes that are not part of this branch, getting merged into trunk. What am I doing wrong ?

SVN Version :

Subversion command-line client, version 1.6.16-SlikSvn-tag-1.6.16@1076804-WIN32.

4
I know this is not an answer, but if you have several active branches simultaneously, then probably you'd better moved to mercurial or git. Ps: I'm not a fanatic, I've been working with svn for ~7 years ;-)zerkms
What advantage does it provide? Why moving to git or mercurial is a better choice?Vanchinathan Chandrasekaran
because git and mercurial have much better support of branches. Advantages: you'll not ask such questions and will have less headaches on creating and maintaining branches (currently I'm working in a project with > 1000 branches, in svn it was a hell to work with them)zerkms
I recommend looking into Svnmerge.py and reviewing this article.chown

4 Answers

220
votes

Your svn merge syntax is wrong.

You want to checkout a working copy of trunk and then use the svn merge --reintegrate option:

$ pwd
/home/user/project-trunk

$ svn update  # (make sure the working copy is up to date)
At revision <N>.

$ svn merge --reintegrate ^/project/branches/branch_1
--- Merging differences between repository URLs into '.':
U    foo.c
U    bar.c
 U   .

$ # build, test, verify, ...

$ svn commit -m "Merge branch_1 back into trunk!"
Sending        .
Sending        foo.c
Sending        bar.c
Transmitting file data ..
Committed revision <N+1>.

See the SVN book chapter on merging for more details.


Note that at the time it was written, this was the right answer (and was accepted), but things have moved on. See the answer of topek, and http://subversion.apache.org/docs/release-notes/1.8.html#auto-reintegrate

80
votes

If your working directory points to the trunk, then you should be able to merge your branch with:

svn merge https://HOST/repository/branches/branch_1

be sure to be to issue this command in the root directory of your trunk

16
votes

Do an svn update in the trunk, note the revision number.

From the trunk:

svn merge -r<revision where branch was cut>:<revision of trunk> svn://path/to/branch/branchName

You can check where the branch was cut from the trunk by doing an svn log

svn log --stop-on-copy
1
votes

The syntax is wrong, it should instead be

svn merge <what(the range)> <from(your dev branch)> <to(trunk/trunk local copy)>