Ubuntu中SVN的安装和使用

安装

sudo apt-get install subversion

常用指令(命令中解释了常用的option的用法,忽略了生僻的option)

1. 将文件(项目)checkout到本地目录

svn checkout srcURL --username ARG --password ARG

例如:svn checkout http://www.mycodesvn.com/main --username Fowler --password 123456

简写 svn co

注:ARG 为 argument(参数)简写

2. 将文件添加到版本库中

svn add ARG

例如:svn add myFile.java

svn add *.java 将当前目录中所有.java文件添加到版本库中

注:这里的添加到版本库,与commit要区分开,add并只是将文件添加到版本库中,还没有提交到服务器,当下一次commit的时候,才会提交到svn服务器。参见英文对svn add的注解:

Put files and directories under version control, scheduling them for addition to repository. They will be added in next commit.

3. 将改动的文件提交到版本库

svn commit -m ARG1 ARG2

ARG1:注释,必填的,但是可以是空串

ARG2:文件目录

例如:svn commit -m "this is my first commit" MyTest.java

英文注解:commit (ci): Send changes from your working copy to the repository.

A log message must be provided, but it can be empty. If it is not given by a --message or --file option, an editor will be started.

If any targets are (or contain) locked items, those will be unlocked after a successful commit.

4.加锁/解锁

svn lock -m ARG1 [--force] ARG2

ARG1:注释

ARG2:文件目录

--force:使用此选现可以从其他的user或者working copy强制获得lock

英文注解:lock: Lock working copy paths or URLs in the repository, so that no other user can commit changes to them.

相应的解锁:svn unlock

5. 更新到某个版本

svn update -r ARG1 ARG2

ARG1: 版本号

ARG2: 文件目录

英文注解:update (up): Bring changes from the repository into the working copy.

If no revision is given, bring working copy up-to-date with HEAD rev. Else synchronize working copy to revision given by -r.

For each updated item a line will start with a character reporting the action taken. These characters have the following meaning:

A Added

D Deleted

U Updated

C Conflict

G Merged

E Existed

6. 查看文件或者目录状态

svn status path (显示目录下的文件和子目录的状态,正常状态不显示)

【?:不在svn的控制中;M:内容被修改;C:发生冲突;A:预定加入到版本库;K:被锁定】

svn status -v path

第一列保持相同,第二列显示工作版本号,第三和第四列显示最后一次修改的版本号和修改人。

英文注解:status (stat, st): Print the status of working copy files and directories.

With no args, print only locally modified items (no network access).

With -q, print only summary information about locally modified items.

With -u, add working revision and server out-of-date information.

With -v, print full revision information on every item.

7. 删除文件

svn delete ARG1 -m ARG2

ARG1:文件目录(路径)

ARG2:注释信息

英文注解:delete (del, remove, rm): Remove files and directories from version control.

1. Each item specified by a PATH is scheduled for deletion upon the next commit. Files, and directories that have not been committed, are immediately removed from the working copy unless the --keep-local option is given.

PATHs that are, or contain, unversioned or modified items will not be removed unless the --force option is given.

2. Each item specified by a URL is deleted from the repository via an immediate commit.

8. 查看日志

svn log ARG

ARG:文件或者文件夹路径

英文注解:log: Show the log messages for a set of revision(s) and/or file(s).

Print the log messages for a local PATH (default: '.'). The default revision range is BASE:1.

9. 查看文件详细信息

svn info path

英文注解:info: Display information about a local or remote item.

Print information about each TARGET (default: '.').

TARGET may be either a working-copy path or URL. If specified, REV determines in which revision the target is first looked up.

10. 比较差异

svn diff path(将修改的文件与基础版本比较)

svn diff -r m:n path(对版本m和版本n比较差异)

11. 将两个版本之间的差异合并到当前文件

svn merge -r m:n path(将版本m与n之间的差异合并到当前文件,但是一般都会产生冲突,需要处理一下)

12. 解决冲突

svn resolved: 移除工作副本的目录或文件的“冲突”状态。