11.07.2015 Views

Version Control with Subversion - Login

Version Control with Subversion - Login

Version Control with Subversion - Login

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Branching and MergingSecond, it's not very flexible. If you do your work on different computers (perhaps you havea working copy of /calc/trunk on two different machines), you'll need to manually copyyour changes back and forth or just do all the work on a single computer. By that sametoken, it's difficult to share your changes in progress <strong>with</strong> anyone else. A common softwaredevelopment “best practice” is to allow your peers to review your work as you go. If nobodysees your intermediate commits, you lose potential feedback and may end up going downthe wrong path for weeks before another person on your team notices. Finally, when you'refinished <strong>with</strong> all your changes, you might find it very difficult to remerge your final work <strong>with</strong>the rest of the company's main body of code. Sally (or others) may have made many otherchanges in the repository that are difficult to incorporate into your working copy—especiallyif you run svn update after weeks of isolation.The better solution is to create your own branch, or line of development, in the repository.This allows you to save your half-broken work frequently <strong>with</strong>out interfering <strong>with</strong> others, yetyou can still selectively share information <strong>with</strong> your collaborators. You'll see exactly howthis works as we go.Creating a BranchCreating a branch is very simple—you make a copy of the project in the repository usingthe svn copy command. <strong>Subversion</strong> is able to copy not only single files, but whole directoriesas well. In this case, you want to make a copy of the /calc/trunk directory. Whereshould the new copy live? Wherever you wish—it's a matter of project policy. Let's say thatyour team has a policy of creating branches in the /calc/branches area of the repository,and you want to name your branch my-calc-branch. You'll want to create a new directory,/calc/branches/my-calc-branch, which begins its life as a copy of /calc/trunk.You may already have seen svn copy used to copy one file to another <strong>with</strong>in a workingcopy. But it can also be used to do a “remote” copy entirely <strong>with</strong>in the repository. Just copyone URL to another:$ svn copy http://svn.example.com/repos/calc/trunk \http://svn.example.com/repos/calc/branches/my-calc-branch \-m "Creating a private branch of /calc/trunk."Committed revision 341.This command causes a near-instantaneous commit in the repository, creating a new directoryin revision 341. The new directory is a copy of /calc/trunk. This is shown in Figure4.3, “Repository <strong>with</strong> new copy”. 1 While it's also possible to create a branch by usingsvn copy to duplicate a directory <strong>with</strong>in the working copy, this technique isn't recommended.It can be quite slow, in fact! Copying a directory on the client side is a linear-time operation,in that it actually has to duplicate every file and subdirectory on the local disk.Copying a directory on the server, however, is a constant-time operation, and it's the waymost people create branches.Figure 4.3. Repository <strong>with</strong> new copy1 <strong>Subversion</strong> does not support copying between different repositories. When using URLs <strong>with</strong> svn copy or svnmove, you can only copy items <strong>with</strong>in the same repository.87

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!