名称

svn switch — 把工作拷贝更新到别的URL。

概要

svn switch URL[@PEGREV] [PATH]
switch --relocate FROM TO [PATH...]

描述

The first variant of this subcommand (without the --relocate option) updates your working copy to point to a new URL—usually a URL that shares a common ancestor with your working copy, although not necessarily. This is the Subversion way to move a working copy to a new branch. If specified, PEGREV determines in which revision the target is first looked up. See “使用分支”一节 for an in-depth look at switching.

If --force is used, unversioned obstructing paths in the working copy do not automatically cause a failure if the switch attempts to add the same path. If the obstructing path is the same type (file or directory) as the corresponding path in the repository, it becomes versioned but its contents are left untouched in the working copy. This means that an obstructing directory's unversioned children may also obstruct and become versioned. For files, any content differences between the obstruction and the repository are treated like a local modification to the working copy. All properties from the repository are applied to the obstructing path.

As with most subcommands, you can limit the scope of the switch operation to a particular tree depth using the --depth option. Alternatively, you can use the --set-depth option to set a new “sticky” working copy depth on the switch target. Currently, the depth of a working copy directory can only be increased (telescoped more deeply); you cannot make a directory more shallow.

--relocate选项导致svn switch做不同的事情:它更新你的工作拷贝指向到同一个版本库目录,但是不同的URL(通常因为管理员将版本库转移了服务器,或到了同一个服务器的另一个URL)。

Alternate Name

sw

改变

工作拷贝2

是否访问版本库

选项

--revision (-r) REV
--depth ARG
--set-depth ARG
--ignore-externals
--force
--accept ARG
--quiet (-q)
--diff3-cmd CMD
--relocate FROM TO
--username USER
--password PASS
--no-auth-cache
--non-interactive
--config-dir DIR

例子

如果你目前所在目录vendors分支到vendors-with-fix,你希望转移到那个分支:

$ svn switch http://svn.red-bean.com/repos/branches/vendors-with-fix .
U  myproj/foo.txt
U  myproj/bar.txt
U  myproj/baz.c
U  myproj/qux.c
Updated to revision 31.

为了跳转回来,只需要提供最初取出工作拷贝的版本库URL:

$ svn switch http://svn.red-bean.com/repos/trunk/vendors .
U  myproj/foo.txt
U  myproj/bar.txt
U  myproj/baz.c
U  myproj/qux.c
Updated to revision 31.

提示

如果你不希望跳转所有的工作拷贝,你可以只跳转一部分。

Sometimes an administrator might change the location (or apparent location) of your repository—in other words, the content of the repository doesn't change, but the repository's root URL does. For example, the hostname may change, the URL scheme may change, or any part of the URL that leads to the repository itself may change. Rather than check out a new working copy, you can have the svn switch command “rewrite” your working copy's administrative metadata to refer to the new repository location. If you use the --relocate option to svn switch, Subversion will contact the repository to validate the relocation request (looking for the repository at the new URL, of course), and then do this metadata rewriting. No file contents will be changed as the result of this type of switch operation—this is a metadata-only modification to the working copy.

$ svn checkout file:///var/svn/repos test
A  test/a
A  test/b
…

$ mv repos newlocation
$ cd test/

$ svn update
svn: Unable to open an ra_local session to URL
svn: Unable to open repository 'file:///var/svn/repos'

$ svn switch --relocate file:///var/svn/repos file:///tmp/newlocation .
$ svn update
At revision 3.

警告

小心使用--relocate选项,如果你输入了错误的选项,你会在工作拷贝创建无意义的URL,会导致整个工作区不可用并且难于修复。理解何时应该使用--relocate也是非常重要的,下面是一些规则:

  • 如果工作拷贝需要反映一个版本库的新目录,只需要使用svn switch

  • 如果你的工作拷贝还是反映相同的版本库目录,但是版本库本身的位置改变了,使用svn switch --relocate