[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: how to merge a feature branch back to trunk?

From: Benjamin Smith-Mannschott <bsmith.occs_at_gmail.com>
Date: Sun, 7 Sep 2008 11:38:10 +0200

On Sep 4, 2008, at 16:45, Martin Bischoff wrote:

> I have created a feature branch which I will have to merge back to
> trunk soon. I'd like some advice about how to best perform that merge
> operation.

> Here's the situation:
> - I have created a feature branch on which we have been working for
some time.
> - During that time, only a few commits were made to trunk.
> - These trunk-changes have not been merged to the feature branch (and
> in fact we do not need them to finish the work on the branch).
> - The branch will not be used anymore once its changes have been
> merged back to trunk.

> After reading the documentation, I think I have two options to merge
> the branch back to trunk:
> 1) First merge the trunk changes to the branch, then merge the branch
> back to trunk using the reintegrate option.
> 2) Simply merge the branch back to trunk (called "Merge a range of
> revisions" in TortoiseSVN).

> Will the result be different depending on which approach I'll use?
> What is the recommended way to merge our branch back to trunk?

(You appear to be using svn 1.5 (since it introduced reintegrate). I
haven't gone into that in any depth because I'm only just making the
switch myself. I'm still using 1.4 + svnmerge.py.)

I don't think it much matters, as long as you understand what you're
doing. Here's the rub, as I see it:

(Think of the branch as a set of changes. The question is changes
relative to what?)


You've got changes on the trunk that are not on the branch. By merging
those changes to the branch you've brought your branch up to date with
trunk. The work represented by your branch is now exactly the
difference between the current state (HEAD) of you branch and the
current state (HEAD) of the trunk.

svn merge svn://repo/trunk svn://repo/branch working-copy-of-trunk-head

This means: compute the changes necessary to make svn://repo/trunk
identical to svn://repo/branch and apply exactly those changes to a
working copy svn://repo/trunk.

The safety of this operation depends critically on the fact that
you've previously merged all trunk changes since branch creation to
the branch.

This is the scenario that the merge --reintegrate option in 1.5 is
designed for. See also http://blog.red-bean.com/sussman/?p=92


You've not synced your branch with trunk. The work represented by the
branch is the set of changes between the creation of the branch and
its current state (HEAD). Those are the changes you want to apply to
a working copy of trunk.

To figure out the origin of your branch use

   svn log --stop-on-copy svn://repo/branch

The last entry listed should be the one where the branch was created
(by copying from trunk.) Let's call that revision 100

   svn merge -r100:HEAD svn://repo/branch working-copy-of-trunk

This means: gather all the changes that were made to the branch since
its creation (r100) and apply those changes to a working copy of the

In either case, you'll want to inspect the results of the merge in
your working copy of trunk. Build and run unit tests if you've go
them. If it looks good, commit.

I would also recommend deleting the branch when you are done. You can
always create a new one from trunk if you need to continue work on
this feature.

// Ben

To unsubscribe, e-mail: users-unsubscribe_at_subversion.tigris.org
For additional commands, e-mail: users-help_at_subversion.tigris.org
Received on 2008-09-07 11:38:41 CEST

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.