名称

svn checkout (co) — 从版本库取出一个工作副本。

概要

svn checkout URL[@REV]... [PATH]

描述

Check out a working copy from a repository. If PATH is omitted, the basename of the URL will be used as the destination. If multiple URLs are given, each will be checked out into a subdirectory of PATH, with the name of the subdirectory being the basename of the URL.

选项

--depth ARG
--force
--ignore-externals
--quiet (-q)
--revision (-r) REV

例子

取出一个工作副本到mine目录:

$ svn checkout file:///var/svn/repos/test mine
A    mine/a
A    mine/b
A    mine/c
A    mine/d
Checked out revision 20.
$ ls
mine
$

检出两个目录到两个单独的工作副本:

$ svn checkout file:///var/svn/repos/test \
               file:///var/svn/repos/quiz
A    test/a
A    test/b
A    test/c
A    test/d
Checked out revision 20.
A    quiz/l
A    quiz/m
Checked out revision 13.
$ ls
quiz  test
$

检出两个目录到两个单独的工作副本,但是将两个目录都放到working-copies

$ svn checkout file:///var/svn/repos/test \
               file:///var/svn/repos/quiz \
               working-copies
A    working-copies/test/a
A    working-copies/test/b
A    working-copies/test/c
A    working-copies/test/d
Checked out revision 20.
A    working-copies/quiz/l
A    working-copies/quiz/m
Checked out revision 13.
$ ls
working-copies

如果你打断一个检出(或其它打断检出的事情,如连接失败。),你可以使用同样的命令重新开始或者是更新不完整的工作副本:

$ svn checkout file:///var/svn/repos/test mine
A    mine/a
A    mine/b
^C
svn: The operation was interrupted
svn: caught SIGINT
$ svn checkout file:///var/svn/repos/test mine
A    mine/c
^C
svn: The operation was interrupted
svn: caught SIGINT
$ svn update mine
A    mine/d
Updated to revision 20.
$

If you wish to check out some revision other than the most recent one, you can do so by providing the --revision (-r) option to the svn checkout command:

$ svn checkout -r 2 file:///var/svn/repos/test mine
A    mine/a
Checked out revision 2.
$

Subversion will complain by default if you try to check out a directory atop an existing directory which contains files or subdirectories that the checkout itself would have created. Use the --force option to override this safeguard. When you check out with the --force option, any unversioned file in the checkout target tree which ordinarily would obstruct the checkout will still become versioned, but Subversion will preserve its contents as-is. If those contents differ from the repository file at that path (which was downloaded as part of the checkout), the file will appear to have local modifications—the changes required to transform the versioned file you checked out into the unversioned file you had before checking out—when the checkout completes.

$ mkdir project
$ mkdir project/lib
$ touch project/lib/file.c
$ svn checkout file:///var/svn/repos/project/trunk project
svn: Failed to add directory 'project/lib': an unversioned directory of the sa
me name already exists
$ svn checkout file:///var/svn/repos/project/trunk project --force
E    project/lib
A    project/lib/subdir
E    project/lib/file.c
A    project/lib/anotherfile.c
A    project/include/header.h
Checked out revision 21.
$ svn status wc
M       project/lib/file.c
$ svn diff wc
Index: project/lib/file.c
===================================================================
--- project/lib/file.c	(revision 1)
+++ project/lib/file.c	(working copy)
@@ -3 +0,0 @@
-/* file.c: Code for acting file-ishly. */
-#include <stdio.h>
-/* Not feeling particularly creative today. */

$

As in another other working copy, you have the choices typically available: reverting some or all of those local modifications, committing them, or continuing to modify your working copy.

This feature is especially useful for performing in-place imports of unversioned directory trees. By first importing the tree into the repository, and then checking out new repository location atop the unversioned tree with the --force option, you effectively transform the unversioned tree into a working copy.

$ svn mkdir -m "Create newproject project root." \
      file://var/svn/repos/newproject
$ svn import -m "Import initial newproject codebase." newproject \
      file://var/svn/repos/newproject/trunk
Adding         newproject/include
Adding         newproject/include/newproject.h
Adding         newproject/lib
Adding         newproject/lib/helpers.c
Adding         newproject/lib/base.c
Adding         newproject/notes
Adding         newproject/notes/README

Committed revision 22.
$ svn checkout file://`pwd`/repos-1.6/newproject/trunk newproject --force
E    newproject/include
E    newproject/include/newproject.h
E    newproject/lib
E    newproject/lib/helpers.c
E    newproject/lib/base.c
E    newproject/notes
E    newproject/notes/README
Checked out revision 2.
$ svn status newproject
$