Danra
Danra

Reputation: 9906

"Naive" svn merge from branch into trunk?

I am using TortoiseSVN for my C++ project, and am trying to "reintegrate a branch" back into the trunk.

My case is simple enough so that for every file which has changed in the branch, I would like it to completely overwrite the matching file in the trunk. Unfortunately, TortoiseSVN is smarter than me, so it merges each pair of files - resulting in some inconsistent code. For example, some code lines which have been deleted in the branch are restored in the merged version.

Is there any way to force TortoiseSVN to use the naive merge behaviour of overwriting all the modified files?

Thanks, Dan

Upvotes: 14

Views: 4668

Answers (5)

tzaman
tzaman

Reputation: 47790

Here's how to do it just using SVN (no mucking about in the filesystem):

  1. Check out the trunk revision from which you created the branch (not the HEAD revision).
  2. Commit it to the repository (this undoes all subsequent trunk changes).
  3. Do your reintegrate-merge (your trunk working copy should now be identical to the branch.)
  4. Commit the merged trunk, and you're done!

Upvotes: 7

JXG
JXG

Reputation: 7403

To the best of my knowledge, this is currently impossible in svn, so TortoiseSVN can't help you.

To simplify a little bit (okay, a lot), take the svn update command as an example. If there are modifications in your working copy as well as the repository, but no actual conflicts, svn update will simply merge the repository's changes into your working copy.

I don't think there's a way around this. If you had actual conflicts, you could use the --accept ACTION command-line option to keep only the local changes (for example). But if you want to specify an acceptance action for any file changed in both the repository and working copy, you're unfortunately Out Of Luck.

It occurs to me that asking svn developers for a command-line option for this case might be an idea, not that it would be released in time to help you here.

The conflict-resolution issue I mentioned suggests a hideously ugly hack, which I do not recommend. Using your favorite tools, get a list of the files that changed in the branch. Now, for each file in that list, modify it on the trunk by prepending an unusual character to each line. Commit the changes to the trunk. Merge to bring the branch up to date before reintegrating, but use --accept to prevent any of the horrible trunk files from making it in. Then, reintegrate, again using --accept to overwrite the horrible trunk files.

I should add that you can't do this with TortoiseSVN, at least not obviously, because it doesn't support --accept, at least not that I could find.

Well, I said it was hideously ugly. Don't try this at home! (I certainly haven't.)

Upvotes: 0

Valentin Rocher
Valentin Rocher

Reputation: 11669

A little amelioration to webwesen's answer, since I don't really see a simple way :

  • do a svn export of the branch in some dir
  • copy all files from this dir to the trunk dir
  • commit

Upvotes: 0

Vanessa MacDougal
Vanessa MacDougal

Reputation: 992

The "svn merge" command is designed for this purpose, and will allow you to merge in one step. Instructions here.

Upvotes: -2

webwesen
webwesen

Reputation: 1262

  1. update to the latest on a branch
  2. copy all files somewhere on your workstation
  3. switch branch to trunk
  4. overwrite using regular windows explorer (only changed files will be overwritten)
  5. commit

Upvotes: 0

Related Questions