Hi,
When creating a branch, what are the implications of selecting the following?
Create copy in the repository from:
- HEAD revision in the repository
- Specific revision the repository
- Working copy
Hi,
When creating a branch, what are the implications of selecting the following?
Create copy in the repository from:
In short:
Depending on the purpose for creating the branch, you will usually choose one of the first two options. The third option is probably less commonly used.
You would branch from the HEAD if you want to do some exploratory development for a particular purpose, or you want to start creating a different version for a specific customer or something. You would branch from the past if you need to make a patch to a previously released version of your software.
HEAD revision in the repository SVN takes the Revision with the highest number so the one which was uploaded last.
Specific revision the repository You can select the revision you would like to get.
Working copy The revision like it is right now in your local workspace (not comitted).
HEAD will cause the branch to be a copy of the latest committed version of the repository.
Specific revision will cause the branch to be a copy at a specific point in time of the repository.
Working copy creates a branch based on your working copy's latest revision and then commits to this all of your "in progress" changes as well.
EDIT: An example for choosing Working Copy.
You update your working copy with the latest version of the trunk to start making some minor changes.
You realise after a few hours that the job was bigger than you expected and you should've created a branch.
Creating a branch from Working Copy at this point then effectively creates the branch as if you had done it at the beginning.
"Creating a branch" in svn is really just making a copy of some subset of your repository. In fact, the SVN Book chapter on branching says as much.
If your directory structure looks like this…
and your URL to trunk is: http://example.com/repos/project/trunk
, you would:
make a new branch named beta
from HEAD like so:
svn copy http://example.com/repos/project/trunk http://example.com/repos/project/branches/beta
This will immediately create the new branch in the repository and doesn't do anything to your local copy.
make a new branch named ancient
from an older revision n like so:
svn copy -r n http://example.com/repos/project/trunk http://example.com/repos/project/branches/ancient
This is exactly the same as 1, but uses the specific revision.
make a branch named alpha
from your local copy, assuming your current directory is trunk
:
cd ../
svn cp trunk branches/alpha
This will make the copy you requested, but does it locally. According to the SVN book, this is discouraged because it takes a lot longer than making the copy on the repository server (where the copy operation is essentially free).
There's also this caveat listed when you type svn help copy
:
WARNING: For compatibility with previous versions of Subversion, copies performed using two working copy paths (WC -> WC) will not contact the repository. As such, they may not, by default, be able to propagate merge tracking information from the source of the copy to the destination.
In my experience, way 1 is typically used. 2 is used in some rare cases involving complicated patches to earlier branches, and 3 is never useful (and according to the documentation, slow and possibly dangerous). So stick with 1 unless you have a compelling reason to use one of the other two.