How do I create complex tags?How do I create complex tags?
AnswerSubversion 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;
It is this last area tags that this post considers in more detail. Creating a basic tagCreating 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 taggingSo, 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 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 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 .. If you found this post useful and are keen to learn more about Subversion, you may be interesting in my Subversion Client training course. CategoryTags for this item |



