制作高度自定义的 Subversion 标签的最简单方法是利用 Subversion 客户端所谓的“WC-to-REPO”复制机制——即 svn copy 操作(或它的 GUI 等效项)其“源”是您的工作副本,其“目标”是存储库中的 URL。
假设您想制作一个看起来与您当前的trunk/ 完全相同的标签,但其中的一些文件已删除或修改。首先,在 HEAD 修订版中获取该trunk/ 的本地工作副本(通过svn checkout 或svn update)。现在,修改工作副本,直到它看起来与您想要标记的完全一样。确保对任何添加或删除文件和目录的操作使用 Subversion 操作(svn mkdir、svn add、svn rm、...)。
现在,不要提交您的更改。相反,请使用 svn copy 将您的工作副本复制到新的标签 URL。
$ svn copy . http://svn.myserver.com/repo/tags/my-new-branch -m "Make a custom tag"
Subversion 客户端将有效地在存储库中的标记位置构建它在您的工作副本中找到的内容的副本。
许多项目(如 Subversion 和 ViewVC 项目)正是使用这种方法从发布分支创建发布标签。通常,有一些源代码文件带有软件的版本字符串,并且您不希望未发布的代码带有一个版本字符串,该字符串表明该代码实际上已经发布。因此,在发布分支(例如branches/1.2.x/)中,源代码文件可能具有以下内容:
__version__ = "1.2.4-dev"
一旦发布分支经过测试并准备好发布,项目可以标记该分支,然后在后续提交中通过删除“”来修复__version__字符串-dev" 位。
$ svn checkout .../branches/1.2.x my-working-copy
$ cd my-working-copy
$ # test, test, and test some more
$ svn copy ^/branches/1.2.x ^/tags/1.2.4 -m "Tag the 1.2.4 release (almost)"
$ svn switch ^/tags/1.2.4 # make the working copy temporarily point to the new tag
$ vi ./lib/version.py # change the __version__ string to drop the "-dev"
$ svn commit -m "Just kidding. Now it's *really* 1.2.4."
$ svn switch ^/branches/1.2.x # make the working point back to the release branch
但这意味着有一个时间窗口,其中标签没有您想要的确切信息。
使用 WC-to-REPO 副本非常简单,而且没有竞争条件。
$ svn checkout .../branches/1.2.x my-working-copy
$ cd my-working-copy
$ vi ./lib/version.py # change the __version__ string to drop the "-dev"
$ # test, test, and test some more
$ svn cp . ^/tags/1.2.4 -m "Tag the 1.2.4 release."
此时,您可以做以下两件事之一。您可以将(仍未提交的)本地修改恢复到发布分支:
$ svn revert -R . # undo the local release branch mods
或者,您可以让 和 提交进一步的本地修改,以便为以下未来版本准备分支:
$ vi ./lib/version.py # change the __version__ string now to "1.2.5-dev"
$ svn commit -m "Begin a new release cycle."