119

Using TortoiseSVN, I need to take changes I've done in a branch and then merge them with trunk.

I am the only developer on this project, so I know trunk hasn't changed. I am learning SVN so that eventually my team can use it.

Basically, I want my trunk to look exactly like the branch.

In pre-svn world, I would just copy the files in my branch folder, delete the files in the trunk folder, and then copy branch into trunk.

In TortoiseSVN, I've tried Reintegrate a branch, Merge a range of revisions, and Merge two different trees. Nothing seems to actually change trunk. I've also tried branching on top of the trunk. This gives me an error, saying that the trunk already exists.

Alexander Abakumov
  • 10,817
  • 10
  • 71
  • 111
Brian Bolton
  • 3,543
  • 8
  • 33
  • 42

4 Answers4

158

In your case:

  1. Switch the working copy to the trunk (SVN Switch)
  2. Merge the branch into the working copy (SVN Merge)
  3. Make sure everything still compiles and works
  4. Commit the working copy (the trunk)
  5. Consider killing the branch

In a team environment I would suggest that you first merge the latest modifications from the trunk in your branch, make sure that everything compiles and works, then do the above steps (which will be trivial since you've already tested the changes).


Update

In step 5, I mention killing the branch. That's because once a branch from a feature is in the trunk, it should be considered as part of the trunk. In that case the branch should be killed so that no one keeps working on it. If major modifications are needed for that feature, you should create a new branch for that.

The only branches that I don't kill are maintenance and release branches, unless a particular release is no longer supported.

No matter what, you always have access to every revision so killing a branch is only used to prevent other developers from developing on a dead branch.

Dave Jarvis
  • 28,853
  • 37
  • 164
  • 291
mbillard
  • 36,360
  • 18
  • 71
  • 97
  • The comment you added under step 5 could probably better be step 1? When you want to use "Reintegrate a branch" from the TortoiseSVN Merge dialog, merging all changes from the trunk (or base branch) first is a requirement. – jbvo Feb 17 '11 at 15:41
  • 1
    Is the first step (switch the working copy to trunk) only necessary if don't have a seperate branch and trunk working copy? – Jeff B Nov 30 '11 at 14:57
  • 1
    I think a major piece of detail that's missing here is what folder you click on for each step, so you know the context of each step. – MacGyver Oct 27 '14 at 20:52
10

I think in TortoiseSVN 1.8.5, Merge | Merge two different trees should work. When you merge a branch/tag back to trunk, the trick is that the From URL is the trunk and the To is the tag/branch. Weird but true.

Source: Merging

For directories that not in your working copy but are in the tag/branch you may get conflict errors. Just accept the conflict and redo the merge.

gsamaras
  • 66,800
  • 33
  • 152
  • 256
Kevin Johnsrude
  • 4,272
  • 2
  • 26
  • 52
  • After you follow the instructions on the tortoisesvn site, make sure after the merge, you commit the trunk without modifying anything. I tried unchecking a few things I didn't want committed which was causing some non-recursive commit warning. Also, consider deleting the branch as the instructions say. – goku_da_master Feb 16 '16 at 22:17
6

First switch your working copy to the trunk. Then do a merge range of revisions, from the branch to trunk. Once this dialog is complete the differences will be pending changes in your working copy of trunk. You'll need to commit them just as if you manually made the changes on your working copy.

In my usage, its more typical to keep trunk running and spin branches off at the times of builds. So then the only merge I ever need to do is to get a bug fix out of trunk and put it on the latest build branch and re-release that branch. The easiest way for me to do this, since as you have found merging is clumsy at best. Is to keep the latest branch and the trunk checked out to my machine, and to quite literally copy the files from trunk to branch and check both in.

DevelopingChris
  • 36,999
  • 27
  • 83
  • 117
  • 2
    Much care should be taken with "copying" the files. Use something like TortoiseSVN's export in order to avoid corrupting the hidden svn directories. – Milimetric Dec 08 '11 at 15:24
3

I am using TortoiseSVN 1.9.3, Build 27038.

Follow below steps in order to merge branch into trunk.

1) Right click on trunk working copy and select the below option.

enter image description here

2) In case of Branch Merging into trunk select option second as shown below and click next

enter image description here

3) In the From: field enter the full folder URL of the trunk. This may sound wrong, but remember that the trunk is the start point to which you want to add the branch changes. In the To: field enter the full folder URL of the feature branch.

enter image description here

4) Click next and do the test merge

enter image description here

5) If test merge is successful then click on Merge button.

6) Once merge is successful then commit the changes on trunk.

Waqas Ahmed
  • 3,743
  • 3
  • 31
  • 42