Question

I followed following steps to merge my branch to trunk.

Check out a copy of trunk:

svn co svn+ssh://server/path/to/trunk

Check out a copy of the branch you are going to merge:

svn co svn+ssh://server/path/to/branch/myBranch

Change your current working directory to “myBranch” Find the revision “myBranch” began at:

svn log --stop-on-copy

This should display back to you the changes that have been made back to the point the branch was cut. Remember that number (should be rXXXX, where XXXX is the revision number). Change your current working directory to trunk # Perform an SVN update:

svn up

This will update your copy of trunk to the most recent version, and tell you the revision you are at. Make note of that number as well (should say “At revision YYYY” where YYYY is the second number you need to remember). Now we can perform an SVN merge:

svn merge -rXXXX:YYYY svn+ssh://server/path/to/branch/myBranch

After merging, if i checked in the reults, should my branch get deleted? I need to retain my branch (I need to continue development in this old branch).

Was it helpful?

Solution

I'm not sure what you're doing. You only need to checkout the branch you are merging to. There's no need to checkout both branches, do a switch, change your working copy, do a log, etc. It's really a fairly simple procedure:

  • You make a branch (we'll call the copy branch) off of the original branch (normally trunk, but that's not necessarily always the case).
  • You can do your work on both original and the copy branch depending upon your development technique.
  • When you want to do a merge, you checkout a copy of the branch you are merging to. This, after all, is the branch getting the changes. You want to test these merged changes before committing them back to the repository.
  • To do a merge, all you have to do is use the svn merge command on your working copy. If you're merging from the original branch to the copy branch, you don't use the --reintegrate switch. If you're merging from the copy branch to the original, you use the --reintegrate switch.

That's all there is to it. You can pick and choose revisions you want to merge, or you can simply allow all changes to be merged. Subversion merging is pretty good and Subversion does a pretty good job at tracking merges.

I suggest you read up on the Subversion manual's chapter on branching and merging.

Do you need to delete a branch you merged from? No. Subversion since version 1.5 won't duplicate a merge that's already happened.

You may delete a branch if it is no longer needed. For example, I make a Release 1.2 branch. I do Release 1.2.1 and Release 1.2.2 on it. However, none of my users are on Release 1.2.x and I no longer do any work on it. I might delete it just because when I do svn ls http://server/svn/branches, I won't see it. Being Subversion, I could move it out of the way if deleting it makes me nervous. I can move it to http://server/svn/branches/OBSOLETE/1.2. That way, it doesn't show up when I list the branches, but it's still there if I ever decide I really, really still need it.

By the way, Subversion never really ever deletes anything permanently. Even if I delete the branch, I can always get it back.

OTHER TIPS

What you want to do is rather simple with SVN 1.8 and explicitly supported with sync merging and automatic reintegration. Here are the commands (documentation and links below will confirm this):

cd path/to/branch/myBranch
svn up
svn merge ^/path/to/trunk  # usually just: svn merge ^/trunk
svn ci -m "Merged changes from trunk."

cd path/to/trunk
svn up
svn merge ^/path/to/branch/myBranch
svn ci -m "Reintegrated branch."

From http://svnbook.red-bean.com/en/1.8/svn.branchmerge.basicmerging.html on "Reintegrating a Branch" says this:

If you choose not to delete your branch after reintegrating it to the trunk you may continue to perform sync merges from the trunk and then reintegrate the branch again[37]. If you do this, only the changes made on your branch after the first reintegrate are merged to the trunk.

You can merge from your branch into trunk at any time, and you don't have to delete it if you still need it around. I would however merge from trunk into your branch so that you keep up with mainline development as well. Also doing this allows you to use the Re-integrate branch feature of SVN, which should make merging changes from your branc back to trunk a bit easier.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top