Tools 'n' Tips Subversion Subversion FAQ Subversion How do I create complex tags?

Tools 'n' Tips

Favourites Create PDF Email Print

How do I create complex tags?

How do I create complex tags?

Author:
Mark Bools
Date added:
Friday, 04 December 2009
Last revised:
Friday, 04 December 2009
Hits:
2046
Rating:
 
Vote for this:
Good - Bad
favoured:
0 Favour

Answer

Subversion does not support labels as many version control tools do. Instead Subversion uses the svn copy command to create 'tags'.

By convention a Subversion repository is often divided into three sub-directories;

  • trunk, where the main development is often (though not necessarily) done;
  • branches, where (unsurprisingly) we maintain branches that may be used for any number of reasons to isolate some sequence of changes from the trunk;
  • tags, where we maintain tagged sets of files and directories.

It is this last area tags that this post considers in more detail.

Creating a basic tag

Creating a simple tag is incredibly fast and simple. Simply copy the thing to be tagged into the tags directory.

svn copy http://subversion/myrepo/trunk http://subversion/myrepo/tags/release_1.0

This command creates a copy of the current revision of the trunk in tags/release_1.0. Creating this copy is very quick and requires almost no resources in the repository's virtual file system.

Selectively tagging

So, creating a straightforward tag is simple but what about more complex tags? What if we want to tag only selected files and directories within our trunk? There are many ways that this can be achieved. We will examine just one of these methods here*. In this example we will create a new working copy for the tag and manually populate it with items from the repository. This method is suitable when using Subversion 1.5+ and provides complete control over what is tagged and how it is recorded in the tag.

First we need to create a working copy to hold the tag. Again, there are several methods of doing this. The method shown here allows the entire tag to be created as a single transaction (more closely emulating the creation of simple tags).

svn co --depth=empty http://subversion/myrepo/tags
svn mkdir tags/mynewtag

These first two commands checkout the tags directory (but none of the existing tags are checkout because we have specified --depth=empty. The mkdir command then creates an empty directory mynewtag in the tags working copy.

We have not yet created a tag in the repository's virtual file system, but we have prepared a working copy which, when committed will do just that. Having prepared our working copy we now copy items into it. In this example we are copying items from the repository into the working copy.

cd tags/mynewtag
svn copy http://subversion/myrepo/trunk/file1.txt .
svn copy --parents http://subversion/myrepo/trunk/dir1/file2.txt dir1/file2.txt

Notice that when copying files into nested directories I have chosen to preserve the directory structure. Using the --parents option ensures that all the necessary intermediate directories are created and scheduled for addition as part of the copy operation. We do not have to preserve the directory structure.

svn copy http://subversion/myrepo/trunk/dir1/file3.txt file3.txt

This command will create a tagged version of the dir1/file3.txt in tags/mynewtag/file3.txt. Similarly we can rename files, or assign them into other directories.

We can also tag complete sub-directories just as simply.

svn copy http://subversion/myrepo/trunk/dir2 dir2

This tags the whole trunk/dir2 as tags/mynewtag/dir2.

Using the --revision option we can control precisely which revisions are tagged (the default being HEAD).

svn copy --revision 4 http://subversion/myrepo/trunk/dir3 dir3

This command tags the revision 4 of trunk/dir3 as mynewtag/dir3.

Once we are happy that our mynewtag working copy contains all of the items we want in the tag, we commit the entire working copy to create the tag in the repository.

cd ..
svn commit -m "Create mynewtag" .

If you found this post useful and are keen to learn more about Subversion, you may be interesting in my Subversion Client training course.

Category

Tags for this item