Working with Subversion Commands: How To 

http://www.ddj.com/linux-open-source/201200496?pgno=3

Getting the most out of Subversion means doing those oft-repeated tasks with ease. Here, we shall quickly cover the basic commands and related switches that are most needed for novice users to get started with SVN.

Where Is My Working Copy? 

To update the newly created repository, can be updated further, a local WC (an exact replica of the repository in its current form) should first be created. The command to create a local copy of the repo and its output is shown below.

[Note]

The last argument (testrepo_copy) to svn co is optional; if no argument is given, then the name of the repository is given to the directory that will hold the working copy. It is in the WC directory that the repository contents will be dumped:

sh-3.1$ /opt/svn-1.4.3/bin/svn co \
  file:///lnx_data/repos_holder/testrepo/trunk testrepo_wcopy
A    testrepo_wcopy/bar.pm
A    testrepo_wcopy/Makefile
A    testrepo_wcopy/foo.pl
Checked out revision 1.

Adding New Files to the Repository 

Previously, I showed how to populate an empty repository using svn import. Subversion assumes that, prior to import, the directory hierarchy is well organized in terms of "branches, trunks, and tags" directories. So, how do we add new files or directories after the repository is created? For this situation, the command svn add is very helpful.

Create the new files and directories in the working copy directory and then execute svn add followed by svn commit:

sh-3.1$ /opt/svn-1.4.3/bin/svn add README
A         README
sh-3.1$ /opt/svn-1.4.3/bin/svn commit . -m "new file to the repo" Adding README Transmitting file data . Committed revision 2.

This command comes in handy when the initial data to be imported is quite large, and doing the same via svn add would prove to be roundabout way to achieve the same objective.

How to Propagate Changes to the Repository 

With the svn add command, new files/dirs are added to the WC only but not to the repo yet. This task is accomplished with the command svn commit. New files are committed in the repo, and, upon successful commit, a revision number is shown. This number indicates how many revisions the repository has undergone including the current commit.

How to Create Baselines 

At significant milestones, the repository can be archived using tags (or "identifiers"). In Subversion, tags are nothing but folders that are created with names provided by the user; tags are created using the command "svn copy".

In the course of writing this article, I wanted to record the progress (at random intervals) of the manuscript; hence, I labeled the changes to it using the svn copy command as shown below (here "svnarticle_draft" is the working copy and "/opt/samagdocs" is the repo location):

sh-3.1$ pwd
/home/ram/svnarticle_draft
sh-3.1$ /opt/svn-1.4.3/bin/svn copy -m "sample tag" . \ file:///opt/samagdocs/tags/MANU_01REVIEW_27FEB
Committed revision 37.

Subversion creates an exact replica of contents from the WC to the mentioned folder "MANU_01REVIEW_27FEB" under the "tags" directory of the repo "/opt/samagdocs". To confirm what constitutes this folder, we use the command, svnlook tree, like this:

svnlook tree /filesystem/path/to/repos | grep -A NUM-LINES \
 "tag-folder-name"

This command, svnlook, does not accept a URL to the repo, but the file system path to the repo and the trimmed output of this command is shown below:

sh-3.1$ /opt/svn-1.4.3/bin/svnlook tree /opt/samagdocs/ | grep -A \
 05 "MANU_01REVIEW_27FEB"
 MANU_01REVIEW_27FEB/
  images/
   svn_move.png
   svnignore_cmd.png
   orig_populate_repo.png
   svnserve_multiplerepos.png
   svnserve_configuration.png

How to Work in Isolation 

Subversion, like other version control tools, facilitates working in isolation via branches. Similar to tags, branches can also be created using the command svn copy. Branch creation can be done in two ways, but I will show the simpler and easier method here, which involves complete server-side action without involving the local WC.

The following is the output of svn copy used to create the test branch and then followed by svn look to highlight that the branch creation process is done successfully:

 sh-3.1$ /opt/svn-1.4.3/bin/svn copy \
  file:///lnx_data/repos_holder/testrepo/trunk \
  file:///lnx_data/repos_holder/testrepo/branches/test_branch \
  -m "simulating branch creation"
Committed revision 4.
sh-3.1$ /opt/svn-1.4.3/bin/svnlook tree \ /lnx_data/repos_holder/testrepo/ | grep -A 05 test test_branch/ bar.pm Makefile README foo.pl

Now that a new branch (copy of the latest from the trunk) has been created, you can check out from this namespace, then work from the checked out copy and merge with the trunk as needed.

Branch creation does not grow the repository size; only the changed files are maintained under the newly created "branch-dir", and the rest of the files (untouched/not modified) are referred from the existing tree. This is often referred to as Cheap Copies.

Conclusion 

That's it for now. In the second part of this article, I look at additional subcommands (e.g., svn propedit, svn merge, and others). Access to Subversion repositories via svnserve and http schemes as well as the availability of various third-party tools for Subversion will also be addressed in the second part.

Acknowledgments 

Thanks to the core Subversion team for providing a superb version control tool and the thriving dev and users mailing lists of Subversion, which continue to be a source of gyan (wisdom) for many, including me, because of the immense contribution from the active participants.

Copyright (c) 2007 CMP Technology