<?xml version="1.0" encoding="utf-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Tags</title> <link rel="stylesheet" type="text/css" href="styles.css" /> <meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /> <style type="text/css"> body { background-image: url('images/draft.png'); background-repeat: no-repeat; background-position: top left; /* The following properties make the watermark "fixed" on the page. */ /* I think that's just a bit too distracting for the reader... */ /* background-attachment: fixed; */ /* background-position: center center; */ }</style> <link rel="home" href="index.html" title="Version Control with Subversion [DRAFT]" /> <link rel="up" href="svn.branchmerge.html" title="Chapter 4. Branching and Merging" /> <link rel="prev" href="svn.branchmerge.switchwc.html" title="Traversing Branches" /> <link rel="next" href="svn.branchmerge.maint.html" title="Branch Maintenance" /> </head> <body> <div xmlns="" id="vcws-version-notice"> <p>This text is a work in progress—highly subject to change—and may not accurately describe any released version of the Apache™ Subversion® software. Bookmarking or otherwise referring others to this page is probably not such a smart idea. Please visit <a href="http://www.svnbook.com/">http://www.svnbook.com/</a> for stable versions of this book.</p> </div> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">Tags</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="svn.branchmerge.switchwc.html">Prev</a> </td> <th width="60%" align="center">Chapter 4. Branching and Merging</th> <td width="20%" align="right"> <a accesskey="n" href="svn.branchmerge.maint.html">Next</a></td> </tr> </table> <hr /> </div> <div class="sect1"> <div class="titlepage"> <div> <div> <h2 class="title" style="clear: both"><a id="svn.branchmerge.tags"></a>Tags</h2> </div> </div> </div> <p> <a id="idm5582" class="indexterm"></a> Another common version control concept is a tag. A tag is just a <span class="quote">“<span class="quote">snapshot</span>”</span> of a project in time. In Subversion, this idea already seems to be everywhere. Each repository revision is exactly that—a snapshot of the filesystem after each commit.</p> <p>However, people often want to give more human-friendly names to tags, such as <code class="literal">release-1.0</code>. And they want to make snapshots of smaller subdirectories of the filesystem. After all, it's not so easy to remember that release 1.0 of a piece of software is a particular subdirectory of revision 4822.</p> <div class="sect2"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="svn.branchmerge.tags.mksimple"></a>Creating a Simple Tag</h3> </div> </div> </div> <p>Once again, <span class="command"><strong>svn copy</strong></span> comes to the rescue. If you want to create a snapshot of <code class="filename">/calc/trunk</code> exactly as it looks in the <code class="literal">HEAD</code> revision, make a copy of it:</p> <div class="informalexample"> <pre class="screen"> $ svn copy http://svn.example.com/repos/calc/trunk \ http://svn.example.com/repos/calc/tags/release-1.0 \ -m "Tagging the 1.0 release of the 'calc' project." Committed revision 902. </pre> </div> <p>This example assumes that a <code class="filename">/calc/tags</code> directory already exists. (If it doesn't, you can create it using <span class="command"><strong>svn mkdir</strong></span>.) After the copy completes, the new <code class="filename">release-1.0</code> directory is forever a snapshot of how the <code class="filename">/trunk</code> directory looked in the <code class="literal">HEAD</code> revision at the time you made the copy. Of course, you might want to be more precise about exactly which revision you copy, in case somebody else may have committed changes to the project when you weren't looking. So if you know that revision 901 of <code class="filename">/calc/trunk</code> is exactly the snapshot you want, you can specify it by passing <code class="option">-r 901</code> to the <span class="command"><strong>svn copy</strong></span> command.</p> <p>But wait a moment: isn't this tag creation procedure the same procedure we used to create a branch? Yes, in fact, it is. In Subversion, there's no difference between a tag and a branch. Both are just ordinary directories that are created by copying. Just as with branches, the only reason a copied directory is a <span class="quote">“<span class="quote">tag</span>”</span> is because <span class="emphasis"><em>humans</em></span> have decided to treat it that way: as long as nobody ever commits to the directory, it forever remains a snapshot. If people start committing to it, it becomes a branch.</p> <p>If you are administering a repository, there are two approaches you can take to managing tags. The first approach is <span class="quote">“<span class="quote">hands off</span>”</span>: as a matter of project policy, decide where your tags will live, and make sure all users know how to treat the directories they copy. (That is, make sure they know not to commit to them.) The second approach is more paranoid: you can use one of the access control scripts provided with Subversion to prevent anyone from doing anything but creating new copies in the tags area (see <a class="xref" href="svn.serverconfig.html" title="Chapter 6. Server Configuration">Chapter 6, <em>Server Configuration</em></a>). The paranoid approach, however, isn't usually necessary. If a user accidentally commits a change to a tag directory, you can simply undo the change as discussed in the previous section. This is version control, after all!</p> </div> <div class="sect2"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="svn.branchmerge.tags.mkcomplex"></a>Creating a Complex Tag</h3> </div> </div> </div> <p>Sometimes you may want a <span class="quote">“<span class="quote">snapshot</span>”</span> that is more complicated than a single directory at a single revision.</p> <p>For example, pretend your project is much larger than our <code class="filename">calc</code> example: suppose it contains a number of subdirectories and many more files. In the course of your work, you may decide that you need to create a working copy that is designed to have specific features and bug fixes. You can accomplish this by selectively backdating files or directories to particular revisions (using <span class="command"><strong>svn update</strong></span> with the <code class="option">-r</code> option liberally), by switching files and directories to particular branches (making use of <span class="command"><strong>svn switch</strong></span>), or even just by making a bunch of local changes. When you're done, your working copy is a hodgepodge of repository locations from different revisions. But after testing, you know it's the precise combination of data you need to tag.</p> <p>Time to make a snapshot. Copying one URL to another won't work here. In this case, you want to make a snapshot of your exact working copy arrangement and store it in the repository. Luckily, <span class="command"><strong>svn copy</strong></span> actually has four different uses (see <a class="xref" href="svn.ref.svn.c.copy.html" title="svn copy (cp)">svn copy (cp)</a> in <a class="xref" href="svn.ref.svn.html" title="svn Reference—Subversion Command-Line Client">svn Reference—Subversion Command-Line Client</a>), including the ability to copy a working copy tree to the repository:</p> <div class="informalexample"> <pre class="screen"> $ ls my-working-copy/ $ svn copy my-working-copy \ http://svn.example.com/repos/calc/tags/mytag \ -m "Tag my existing working copy state." Committed revision 940. </pre> </div> <p>Now there is a new directory in the repository, <code class="filename">/calc/tags/mytag</code>, which is an exact snapshot of your working copy—mixed revisions, URLs, local changes, and all.</p> <p>Other users have found interesting uses for this feature. Sometimes there are situations where you have a bunch of local changes made to your working copy, and you'd like a collaborator to see them. Instead of running <span class="command"><strong>svn diff</strong></span> and sending a patch file (which won't capture directory or symlink changes), you can use <span class="command"><strong>svn copy</strong></span> to <span class="quote">“<span class="quote">upload</span>”</span> your working copy to a private area of the repository. Your collaborator can then either check out a verbatim copy of your working copy or use <span class="command"><strong>svn merge</strong></span> to receive your exact changes.</p> <p>While this is a nice method for uploading a quick snapshot of your working copy, note that this is <span class="emphasis"><em>not</em></span> a good way to initially create a branch. Branch creation should be an event unto itself, and this method conflates the creation of a branch with extra changes to files, all within a single revision. This makes it very difficult (later on) to identify a single revision number as a branch point.</p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="svn.branchmerge.switchwc.html">Prev</a> </td> <td width="20%" align="center"> <a accesskey="u" href="svn.branchmerge.html">Up</a> </td> <td width="40%" align="right"> <a accesskey="n" href="svn.branchmerge.maint.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">Traversing Branches </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> Branch Maintenance</td> </tr> </table> </div> <div xmlns="" id="vcws-footer"> <hr /> <img src="images/cc-by.png" style="float: right;" /> <p>You are reading <em>Version Control with Subversion</em> (for Subversion 1.8), by Ben Collins-Sussman, Brian W. Fitzpatrick, and C. Michael Pilato.</p> <p>This work is licensed under the <a href="http://creativecommons.org/licenses/by/2.0/">Creative Commons Attribution License v2.0</a>.</p> <p>To submit comments, corrections, or other contributions to the text, please visit <a href="http://www.svnbook.com/">http://www.svnbook.com/</a>.</p> </div> </body> </html>