tags:

views:

1665

answers:

3

Let's say people have been working on the trunk and on a branch of a Subversion repository. I want to discard any changes on the trunk, and replace it with a copy of the branch.

As suggested in another question, I can just move or remove the trunk, and then copy the branch over to the trunk. But then the trunk's history is replaced with the branch's history. What if I want to retain the trunk's history?

I think what I want is something like a merge, but one where the destination's changes are ignored, and just replaced with the source. How would I do this in Subversion? Is this considered good practice?

+2  A: 

merge all changes from the branch to the trunk. then resolve all conflicts with

svn resolve path --accept theirs-full

Or, you can tell the merge to do that:

svn merge -rX:HEAD url/of/branch trunk\wc --accept theirs-full

After such a merge, you have a working copy which looks like the one on the branch. All you have to do is commit that trunk working copy.

Stefan
won't that preserve the changes made on trunk since the branch point (at least when it's not conflicted)? I'm pretty sure the result of such a merge is not guaranteed to look like the trunk, but you are the expert...
rmeador
you could first do a reverse merge on the trunk to undo all the changes since you created the branch, then commit that reverse merge. After that, you can merge the branch to the trunk.
Stefan
what about a simple 'svn rm trunk' followed by 'svn copy branch trunk' (or svn move branch trunk)?
David Rodríguez - dribeas
A: 

I'm not quite sure I undestand what you're trying to do. What do you want to have happen to all the changes made on trunk after the branch was created? Do you want them to not appear in the log when you view the history of a file after the merge? If so, that's what you'll get if you delete the trunk and copy the branch into its place -- the branch shares the history with trunk prior to being branched, so it's the same except for the revisions made after the branch. If you want to keep the history of trunk, but just stomp on all the changes made between branching and merging, that's a slightly trickier problem. I think if you do a merge that ignores ancestry (there's an option --ignore-ancestry), it will replace the contents of trunk with the branch. You may also want to try the --force option with the merge (both in lieu of and in conjuction with --ignore-ancestry). Try it a couple different ways to see if you get the results you want...

If that fails, you could always reverse-merge all the changes on trunk since the branch point, then merge in the branch. This seems likely to cause some conflicts, which you would of course want to resolve using the version from your branch. I don't know if any of these ideas are optimal.

rmeador
I want the second of your two options -- stomp on all the changes in the trunk.
JW
+1  A: 

Pre-1.5 this is simple: make sure your working copy points to trunk, then do "svn merge url-of-trunk url-of-branch". The changes you receive are the delta between trunk and branch, effectively "give me everything that's needed to make trunk look like branch."

I have no idea if 1.5's new merge capabilities change this scenario.

Rytmis