Tuesday, March 20, 2012

Creating SVN Tag

If you want to create a copy of your  svn trunk exactly as it looks in the HEAD revision. svn copy comes to the rescue.

 $ svn copy http://svn.host.com/repository/project/trunk    http://svn.host.com/repository/project/tags/release_X_X    -m "Tagging the release X_X of project."




This example assumes that a /project/tags directory already exists. (If it doesn't, you can create it using svn mkdir.) After the copy completes, the new release-X_X directory is forever a snapshot of how the /trunk directory looked in the HEAD 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 /project/trunk is exactly the snapshot you want, you can specify it by passing -r 901 to the svn copy command.
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 tag is because humans 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.