views:

239

answers:

4

I probably just haven't thought this through, or perhaps I'm simply unaware of an already existing option in Subversion (I'm certainly no expert).

I'm just wondering, if I've created a branch to start working on some new feature, if there's an easier way to keep the branch up to date with the trunk's most recent revisions without having to go through all the trouble of merging a range of revisions. I would like to be able to simply update and get all revisions from the trunk (and the branch, of course), while my committed changes only affect the branch. Is this possible? Does what I'm asking make sense?

I suppose this isn't really necessarily different from merging a range of revisions; it's just that I use AnkhSVN, which performs all these best-practice checks before allowing a merge, and sometimes it feels like it's a lot more complicated than it needs to be. The idea is that I want to keep my branch up-to-date with any commits other developers may be making to the trunk so that when I eventually do merge my branch into the trunk, everything goes (as) smoothly (as possible).

A: 

I'm not familiar with AnkhSVN, but what you're describing is exactly what svn merge is for. So the answer to your question is no.

However, you might check out the --reintegrate option to see if that makes your life easier.

See these blog posts:

Subversion merge reintegrate
Subversion 1.5 merge-tracking in a nutshell

Michael Hackner
The first part of this answer is good, but the --reintegrate option is used when merging the branch back to trunk, so it is not really applicable to the question.
ChrisH
@ChrisH He specifically mentioned merging back to trunk as the last step in the process, so I included it for completeness.
Michael Hackner
@Michael Hackner - Fair enough. I just thought it could use some clarification because using --reintegrate when going from trunk to branch would cause problems. In retrospect I should have worded my first comment as a clarification.
ChrisH
+1  A: 

The idea is that I want to keep my branch up-to-date with any commits other developers may be making to the trunk so that when I eventually do merge my branch into the trunk, everything goes (as) smoothly (as possible).

To achieve that you need to do range-revision merges from trunk. Actually, it is a good practice to do this kind of merge to a branch from time to time to be up-to-date with what is going on in the trunk.

I don't know about the tools for AnkhSVN, but 'pure' SVN has very good tools that make merge operations quite simple. TortoiseSVN is a great tool for Windows and if you like Netbeans there is a very nice graphical support for merge too.

pajton
+5  A: 

Keeping your branch up to do date with the latest trunk check-ins is called a merge.

I know merging can be a royal nightmare sometimes, but this is precisely what merging is.

Jack Marchetti
@Jack: I suspected this would be the general answer. Perhaps my question should have been, then, why is merging so much more involved than simply updating?
Dan Tao
Because merging has to deal with _conflicting_ changes?
sbi
@sbi: So does updating, though, potentially.
Dan Tao
Having trunk and branch means having a 2 lines of development. Think of it as of 2 paths to a root in a tree. If you want to retrieve the changes from the other line it cannot be too simple, right:)?
pajton
@Dan - I think it might just be this difficult in SVN. I recall listening to stackoverflow podcast where Joel/Jeff spoke about how painful this can be. I'm not sure if other Source Control systems do it better.
Jack Marchetti
@pajton: I can see how it must be more complex than a plain vanilla update from the same branch/trunk. But conceptually, I sort of think of the trunk as coming "before" the branch, or in any case being ahead of the branch hierarchically. So I would have liked it if I could continue getting updates from all levels "before" mine--so that I could, for example, branch off a branch, and continue getting all updates from the trunk *as well as* the parent branch. But it seems it's just a pipe dream...
Dan Tao
@Jack: Looks like you're right. After checking out the link provided by Michael Hackner, I think I got a better idea of the issues inherent in updating branch via a system based on revisions.
Dan Tao
@Dan: Yes, updating does that, too, and it, too, hurts sometimes. However, branches are often created because it is _known_ before-hand that conflicting edits will take place over a longer period of time - so it's more likely that you will run into conflicts. (And don't forget those times where you merge two branches with conflicting changes into a working copy with more local changes. That's fun...)
sbi
A few additions to this, if you choose "range of revisions", but don't use the history viewer to select what you want to merge, all revisions are merged. This is controlled from the wizard step right after where you choose "Range of Revisions". If you make sure you don't have uncommited changes, and the whole working copy is at a single revision (update at the solution level before you start merging). AnkhSVN will warn you if this isn't the case.
Sander Rijken
+1  A: 

TL;DR; No you must merge, here's some instructions

It's not as bad as you think it is. I will outline the steps from the commandline that I use. I will be using vimidiff to manage the conflicts you can use Meld or someother diff tool that you like. Commands are preceded by the hash '#' mark

<in branch first time from copy>
# svn log --stop-on-copy | tail 
<read the revision that was the copy instruction in this case r229>
# cd ../../trunk
# svn up
<I make note of the latest rivision which is r334>
<now I go back to the branch>
# cd ../branches/branch 
# svn merge -r229:334 svn://url.to.svn.server/project/trunk
<a whole bunch of stuff happens>
< now I check for conflicts >
# svn status | grep ^C
<which outputs something like>
C       public/tools/Diagnostic.class.php
C       public/domain/Report_Setup_Parameter.class.php
C       public/modules/mReports.module.php
<I now revert all these and manually merge them>
# svn revert public/tools/Diagnostic.class.php
...
<revert done now manuall doinng the merge
# vimdiff public/tools/Diagnostic.class.php ../../trunk/public/tools/Diagnostic.class.php
...
<now all the changes are done>
# svn commit -m "Merging trunk into branch 'branch' r:229:334"
commited revision 335

Done, if you do it reguarly then there are not many changes. After the first merge you need to use the revision # of the last merge. Therefore some time in the future the command would look in the svn log to find when the revision of the last merge was, in this case 335. The merge command would look like thuse

# svn merge -r335:370 svn://url.to.svn.server/project/trunk

All other steps are the same.

flaxeater