Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge branch back to trunk in SVN with all commit history?

Tags:

merge

svn

How to merge branch back to trunk in SVN with all commit history? I know in Git I can use

merge -squash 

Is there any equivalent command in SVN? I am using SVN 1.6.

like image 332
zs2020 Avatar asked Aug 20 '10 14:08

zs2020


People also ask

Do I need to commit after merge SVN?

It never should have been committed. You can use svn merge to “undo” the change in your working copy, and then commit the local modification to the repository. All you need to do is to specify a reverse difference.

How do I merge two SVN revisions?

To merge a range of revisions, use svn merge -r start:end from to where start and end are revision IDs. This will merge all revisions starting at start+1 up to and INCLUDING end . Note: it will NOT include the first revision (ex: -r3:45 will merge 4 through 45).


2 Answers

With Subversion 1.5 or later the merge is recorded on your local working copy in the svn:mergeinfo property. So this information is not lost.

You can see the merged revisions if you use svn log -g instead of the normal svn log.

Normal merges are performed as

svn merge -rREV1:REV2 svn://server/branch my_trunk_wc  

But if you use a branch it is sometimes more convenient to use a reintegration merge. In this case you should first merge all trunk changes to the branch using something like

svn merge svn://server/trunk my_branch_wc 

(This merges everything that is not already merged)

And after you commit this change to the branch you can use

svn merge --reintegrate svn://server/branch my_trunk_wc 

To move all changes over as a single commit. (After this operation you should remove the branch)

like image 158
Bert Huijben Avatar answered Sep 22 '22 17:09

Bert Huijben


To create a merge of a branch and create a single commit for each commit in the branch you can use a script, I'm using the following:

#/bin/bash  BRANCH="http://your branch url"  for i in {1127..1138} # list of revisions do   REV=$i   echo $REV $BRANCH   echo merged $REV from $BRANCH > tmps.commit   svn log -c $REV $BRANCH >> tmps.commit   svn up   svn merge -c $REV $BRANCH ./   svn commit -F tmps.commit   rm tmps.commit done 

This will check out each revision you specify for the specific branch and perform a commit on the current directory, thus preserving each single change with the corresponding message.

like image 41
Elmar Weber Avatar answered Sep 19 '22 17:09

Elmar Weber