30
votes

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?

6
You can still access the trunk's history by browsing old revisions...David Z
But any tool that looks at a file's history (e.g. Subclipse) will only show the revisions on the branch. After the merge/copy, I'd prefer to see one new revision on the trunk, containing all the adds/changes/removes from the copy operation.JW.
+1: I need to do this as well. @JW Did you get this to work?Steven Evers
Not yet...I ended up just doing the straight copy.JW.

6 Answers

37
votes

Though its a pretty old thread but still sharing my experience

We recently did this for one of our projects and followed guidelines as:

svn copy <repos/trunk> <repos/tag/old_trunk> -m "copied old trunk as tag"

svn delete <repos/trunk> -m "deleted trunk temporarily"

svn copy <repos/branch/new_fetaure_branch> <repos/trunk> -m "placed new trunk with features"

Following these steps kept the trunk history intact and replace the new feature branch as trunk.

4
votes

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.

4
votes

Merge all changes from the branch to the trunk, and 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's working copy.

1
votes

I'm not quite sure I understand 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 of 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.

1
votes
trunk       remplace (trunk with your branch)
*----x      * ---->
 \          |
  \         |
   *--------|
     branch 

This branch was created from trunk so be careful of do not delete brutally the trunk (problems with the ancestry). First make a tag with your trunk, your backup, in any case...

I suggest do like this:

Using Eclipse SVN

  1. click right > Team Branch/tag (create a tag - your backup)

  2. Team > switch another branch/tag ... select your branch, be sure that the branch is correctly loaded.

  3. in the branch : Team > disconnect. Delete SVN info.

  4. Team > share project ... choose your trunk.

  5. Team > commit in your trunk.

  6. click right ... select Compare with.. Branch/tag -> look for your branch. If everything is OK you will have : "There are no differences between the selected inputs."

I hope it helps.

0
votes

I think what you are trying to do is merge two trees. Below I quote the documentation from tortoisesvn (https://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-merge.html)

".... What you are asking Subversion to do is:" Calculate the changes needed to get [From] the trunk head revision [To] the trunk head revision branch, and applying them changes to my working copy (of the trunk). The net result is that the trunk now looks exactly like the branch."

In your case, the trunk is from, and to is the branch

I hope this is helpful