目录
  1. 1. 安装
  2. 2. 配置
  3. 3. 启动服务
  4. 4. SVN操作

安装

 SVN有两种运行方式:一种是基于Apache Http Server,另外一种是Subversion Standalone Server。以下主要以Apache方式为主。

1
yum install httpd httpd-devel subversion mod_dav_svn

 检查Apache的SVN模块

1
2
3
[root@~]# ls /etc/httpd/modules/|grep svn
mod_authz_svn.so
mod_dav_svn.so

 检查SVN安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@~]# svn --version

svn, version 1.6.11 (r934486)
compiled Jul 23 2015, 23:48:52

Copyright (C) 2000-2009 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following repository access (RA) modules are available:

* ra_neon : Module for accessing a repository via WebDAV protocol using Neon.
- handles 'http' scheme
- handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
- with Cyrus SASL authentication
- handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
- handles 'file' scheme

配置

 需要对ApacheSVN进行配置

  • SVN配置
     使用svnadmin命令创建项目

    1
    2
    3
    4
    mkdir -p /www/svn
    cd /www/svn
    svnadmin create pycode
    chown apache.apache -R pycode/
  • Apache配置
     配置文件:/etc/httpd/conf.d/subversion.conf

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    <VirtualHost *:8888>
    ServerName moglsvn.com
    <Location /svn >
    #Options Indexes FollowSymLinks

    #启用WebDAV的SVN
    DAV svn

    #若目录下有多个版本库则使用SVNParentPath,只有一个时可使用SVNPath
    SVNParentPath /www/svn/
    #SVNPath /www/svn/project_name

    #允许显示父目录
    SVNListParentPath on

    #开启验证
    AuthType Basic
    AuthName "pxe_tmp svn"
    AuthUserFile /www/svn/svnconfig/passwd
    AuthzSVNAccessFile /www/svn/svnconfig/authz
    Require valid-user
    </Location>
    </VirtualHost>
  • 创建SVN用户
     首次创建需要-c参数,后续添加用户必须去掉-c参数否则会先清空文件再创建!
    svnconfig目录下有passwdauthz文件,passwd文件记录用户及密码、authz为权限控制文件

    1
    2
    mkdir /www/svn/svnconfig
    htpasswd -c /www/svn/svnconfig/passwd username
  • 权限分配
     编辑/www/svn/svnconfig/authz配置文件,设定分组以及目录权限
    * =表示未授权用户禁止访问

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    [groups]
    admin = mogl,admin
    test = test

    [pycode:/]
    @test = r
    * =

    [shellcode:/]
    @admin = rw
    * =

启动服务

 配置完后启动Apache即可访问

1
/etc/init.d/httpd start

 假若没安装apache而是使用Subversion Standalone Server方式则需要启动svnserver,Subversion Standalone Server方式每次修改配置文件后都需要重启svnserver

1
svnserve -d -r /www/svn/

SVN操作

 使用命令方式操作SVN

####创建分支
 如果使用了apache,checkout地址可为http方式且不需要运行svnserver;如果没使用apache则必须运行svnserver

  • http方式

    1
    2
    3
    svn checkout http://10.0.2.31:8888/svn/pycode/
    #简写
    svn co http://10.0.2.31:8888/svn/pycode/
  • svnserver方式

    1
    svn checkout svn://10.0.2.31/svntest

####提交代码
 分支创建后,修改代码需要提交到SVN服务器上。-m为说明

1
2
3
svn commit -m 'svninit.py commit checkout' svninit.py
#简写
svn ci -m 'svninit.py commit checkout' svninit.py

####导入
 假若项目开始前没有版本管理,现在需要接入到SVN进行版本管理就需要用到import导入

1
svn import /local/path/project_name/ file:///www/svn/project_name -m 'new project import to svn'

####新增文件
 当有新文件产生需要提交时,必须先addcommit

1
2
svn add file1.txt
svn ci -m 'add new file1.txt' file1.txt

####更新文件
 当SVN服务器的代码文件有更新变动时,想要本地代码达到最新状态则需要update。但如果本地文件更新变动后如果没有commit,当执行update并不会覆盖本地文件,所以本地代码更新后务必commit提交到SVN服务器

1
2
3
4
5
6
7
8
9
#递归更新目录下的文件
svn update
#只该更新文件
svn update filename
#简写
svn up

#更新到指定版本
svn up -r 2 filename

####删除文件
 删除文件和新增文件类型,都是先本地操作后提交SVN(必须提交否则SVN服务器无变动)

1
2
3
4
svn delete filename
svn ci -m 'delete filename by username' filename
#简写
svn del

####查看信息

1
2
svn log
svn info

####比较差异
 比较版本2和版本1之间的差别

1
2
svn diff -r 2:1
svn diff -r 2:1 filename

 为diff添加颜色

1
2
3
yum -y install colordiff
vim ~/.subversion/config
diff-cmd = colordiff

####恢复
 假若在本地编辑代码后,没有commit,需要取消所有的本地编辑则可用revert操作

1
2
3
svn revert filename
#恢复整个目录
svn revert --recursive

Powered: Hexo, Theme: Nadya remastered from NadyMain