tags:

views:

811

answers:

4

I have some commits that I've decided, after the fact, are going to be more branch work then trunk work. How do I create the branch and revert the trunk while still ensuring merging isn't painful later?

Is it as simple as copying the current trunk to a branch and reverting the trunk? Or will this create headaches later?

+1  A: 

There's nothing wrong with following Philip's method, other than it leaves some "cruft" in the revision history. If you wanted to removed them for tidiness sake, and the revisions are at HEAD you could remove them from the repository by following these instructions.

Update: Philip's method is better than the one suggested in the question for the reasons he stated. Mine and Philip's methods would be similar, except that insead of reverting the trunk I propose removing the revisions from the revision history. (as I said, this can only be done if all the revisions you want to remove are at the HEAD of the repository.)

Sam Hasler
Could you elaborate as to what that's doing and why? Why can't I do the suggested method in the question?
TheDeeno
The procedure you posted in your question works fine. The only drawback is that it leaves an extra commit and revert in the log. Sam Hasler's link can help clean out those extra entries, but it's strictly optional.
AaronSieb
As Aaron says, you don't have to remove the commits, it's strictly optional. If you don't think having the extra commits in the history would be confusing at any point then by all means don't bother. It's only if they could cause problems that you should bother removing them.
Sam Hasler
Yeah, not totally comfortable messing with the db. If a totally clean repo was a requirement I'd probably use this method to help out.
TheDeeno
+1  A: 

To be honest, I copy my changes off, revert trunk, branch, then commit my changes to the branch. The main reason being ease of merge later (if you later merge from the trunk to the branch at branch point, the merge will contain a revert of your initial changes).

This may not be the "correct" way, as you can always skip revisions when merging, but it is normally much less of a headache for me later on. Disclaimer: I'm no svn guru, so it may be easier for me because I'm doing it wrong - but I do use svn quite a lot.

Philip Rieck
I figured it would make merging a pain. Thanks for the answer
TheDeeno
A: 

I don't have svn available right here but this is how I would try to do it :

Determine the point in history where you started committing bad stuff (say revision "100" while you are at "130")

svn copy trunk branch # create your branch while preserving history
svn copy trunk@100 trunk #replace current revision with revision 100

This should bypass the bad history without adding a reverse merge (actually you are bypassing the history of the trunk between 100 and 130 but you kept a link to that history in the branch and accessing trunk while forcing the rev will still yield the correct history)

Then

svn switch branch workdir

this should work if you want to completely remove the changes from trunk. If there are small ones you want to keep you can cherry pick them again from branch to trunk (if you use svn 1.5 it will track merge points and avoid spurious conflicts)

Jean
It doesn't let me override the trunk. Fails saying "path 'trunk' already exists". Have you ever done this before? am I doing something wrong?Thanks
TheDeeno
+5  A: 

I think Philips method would be something like the following, assuming the last "good" revision was at 100 and you are now at 130, to create the new branch:

svn copy -r100 svn://repos/trunk svn://repos/branches/newbranch
svn merge -r 100:130 svn://repos/trunk svn://repos/branches/newbranch

Note the idea is to preserve the changes made in those revisions so you can apply them back to trunk.

To revert trunk:

svn merge -r130:100 .
svn ci -m 'reverting to r100 (undoing changes in r100-130)' .

(It wouldn't matter which order you performed these in, so you could revert trunk before creating the branch.)

Then you could switch to the new branch you created in the repo:

svn switch svn://repos/branches/newbranch workdir
Sam Hasler
This is a good solution. I had a similar problem. Only thing that isn't mentioned here is that the merge must be done on a working copy, so you need to check 'newbranch' out.
disown