svn基本操作

1. help

svn help subcommand will describe the syntax, options, and behavior of the subcommand.

2. import

The svn import command is a quick way to copy an unversioned tree of files into a repository, creating intermediate directories as necessary. You typically use this when you have an existing tree of files that you want to begin tracking in your Subversion repository. 例如,假设svn服务器上存在以下目录https://var/svn/newrepos/,本地机器上存在md5目录,并且md5目录下存在md5.c和md5.h两个文件。现在想把md5这个新的项目导入到svn服务器,使其具有版本管理功能。

svn import md5 https://var/svn/newrepos/md5 -m 'Initial md5'

Note that after the import is finished, the original tree is not converted into a working copy. To start working, you still need to svn checkout a fresh working copy of the tree.

3. checkout

Most of the time, you will start using a Subversion repository by doing a checkout of your project. Checking out a repository creates a “working copy” of it on your local machine.

svn checkout https://var/svn/newrepos/md5
svn co https://var/svn/newrepos/md5

While you can certainly check out a working copy with the URL of the repository as the only argument, you can also specify a directory after your repository URL. This places your working copy in the new directory that you name.

svn co https://var/svn/newrepos/md5 my_md5

That will place your working copy in a directory named my_md5 instead of a directory named md5 as we did previously. The directory my_md5 will be created if it doesn’t already exist.

4. Authenticating As a Different User

If you’re working in a shared working copy such as a system configuration directory or a web server document root. In this case,
just pass the —username option on the command line, and Subversion will attempt to authenticate as that user, prompting you for a password if necessary.

svn list https://var/svn/newrepos/md5 --username xiaoming

5. svn export

If you’re building a release and wish to bundle up your files from Subversion but don’t want those pesky .svn directories in the way, you can use svn export to create a local copy of all or part of your repository sans .svn directories.

$ svn export http://svn.example.com/svn/repos1 -r 1729
# Exports revision r1729

6. Examining History

Several commands can provide you with historical data from the repository:

svn log

Shows you broad information: log messages with date and author information attached to revisions and which paths changed in each revision. If you wish to see a different range of revisions in a particular order or just a single revision, pass the —revision (-r) option:

$ svn log -r 5:19 # shows logs 5 through 19 in chronological order
$ svn log -r 19:5 # shows logs 5 through 19 in reverse order
$ svn log -r 8 # shows log for revision 8

In verbose mode, svn log will include a list of changed paths in a revision in its output:

$ svn log -r 8 -v
------------------------------------------------------------------------

r8 | sally | 2008-05-21 13:19:25 -0500 (Wed, 21 May 2008) | 1 line
Changed paths:
M /trunk/code/foo.c
M /trunk/code/bar.h
A /trunk/code/doc/README
Frozzled the sub-space winch.

svn diff

There are three distinct uses of svn diff:

  • Invoking svn diff with no options will compare your working files to the cached “pristine” copies in the .svn area
  • If a single —revision (-r) number is passed, your working copy is compared to the specified revision in the repository
  • If two revision numbers, separated by a colon, are passed via —revision (-r), the two revisions are directly compared:
    svn diff -r 2:3 rules.txt
  • If a “—change(-c) ARG” is passed, it shows the change made by revision ARG(like -r ARG-1:ARG). If ARG is negative this is
    like -r ARG:ARG-1

svn cat

Retrieves a file as it existed in a particular revision number and displays it on your screen

svn list

Displays the files in a directory for any given revision