views:

312

answers:

4

I understand the basic concept of a branch and merge. All of the explanations I've found talk about branching your entire trunk to create a branch project and working on it and then merging it back. Is it possible to branch a subset of a project?

I think an example will help me explain best what I want to do. Suppose I have an application with ten files file0 through file10. All files are interdependent and to be able to test any one file all the others need to be included in the build. I want to work on file0 but don't need to make changes to file1 through file10. Can I branch file0 so changes committed to file0 will update something like myrepos/branches/a-branch/file0 but all the other files in my working copy will simply be from the trunk?

The reason I want to do this is that I'm working on a huge j2ee application with tens of thousands of files and it seems like branching the entire thing will take a really long time. Also, I'm using eclipse with subclipse (and I could be wrong about this) but it seem like if I branch a project in eclipse then I will have to set up a new eclipse project to point to the branch. Unfortunately importing this particular project from SVN to eclipse takes several hours due to the size of the application. It isn't realistic for me to spend this much time.

I suppose that I could have the concepts wrong. Perhaps branching an entire project doesn't require a new working copy at all?

Thanks for any light shed on this issue.

+1  A: 

svn branching is based on lazy copy mechanism, so you can branch safely your all project: that would not take long.

As mentioned in the the question "How do I branch an individual file in SVN?", you could branch a subset, but I believe this would be dangerous with the svn:merginfo properties mechanism: it works better it that property is set from the root of the project.

VonC
It doesn't take long on the *server*. It does require an extra working copy, which appears to be what the questioner is trying to avoid.
quark
@quark, yeah I don't want to have to reimport this project every time I want to branch, but it is sounding like the only way to work it.
quadelirus
+2  A: 

In Subversion, making a branch is simply making a copy of a hierarchy of directories. Therefore, you can branch a subset, but only if that subset can be defined by a hierarchy of directories.

Can I branch file0 so changes committed to file0 will update something like myrepos/branches/a-branch/file0 but all the other files in my working copy will simply be from the trunk?

To answer this question: No, you can't branch a single file. However, what I think you want to do instead is to make a branch and work on file0 there. As you make changes to trunk files, you simply merge them into your branch where you're working on file0.

In this way, you'll always have the latest information from trunk, which will let you test the file0 changes independently of trunk. Then you can use svn switch to move your "file lens" between the trunk and the branch (but beware, Eclipse may complain about such shenanigans).

John Feminella
+1  A: 

Branching in SVN is an O(1) operation. Also, as SVN internally employs lazy copying, you only pay a space penalty for what you change.

So if you are unsure, why not go ahead and branch the whole project?

(As quark mentioned, one problem with branching big projects is that, if you checkout several branches/the trunk in parallel, this might take a lot of local disk space.)

sbi
Again, note what he says about the working copy. If the working copy size isn't an issue, then this is good advice. But with very large working copies this can be a problem.
quark
This can only be a problem if you check them out in parallel. Note that he wrote about _switching_ between branches. However, I agree that a hint regarding the working copy size would be necessary.
sbi
+2  A: 

Branching an entire (even) very large tree in Subversion is a very cheap operation, which does lazy (O(1) time) file copying.

You don't necessarily have to change your entire working copy to work on just one changed file. You can use svn switch to switch one file or one directory in your working copy to be a checked out version of the file on the branch.

Avi
That's your solution quadelirius. Branch the whole project (fast, as all other answerers have noted), and change to the files you care about using svn switch. No extra working copy space. Just don't forget to switch them back when you want to return to trunk.
quark
Yeah, I'm trying this now in eclipse and it is having exactly the effect I was worried about. The branching happened instantly but the svn switch has been running for probably 5 or 6 minutes now because eclipse decided it needed to rebuild the entire project.
quadelirus
25 minutes in an eclipse is still unresponsive.
quadelirus