Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Open Source

Subversion and Linux: Setup and Use, Part 1


Working with Subversion Commands: How To

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.

Acknowledgements

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.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.