1.实验环境
svn server(subversion):192.168.40.129
svn client(TortoiseSVN):下载地址(http://tortoisesvn.net/downloads.html)
2.准备epel源
[root@localhost ~]# rpm -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm Retrieving http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm warning: /var/tmp/rpm-tmp.HjLnDh: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:epel-release ########################################### [100%]更新epel源仓库: [root@localhost ~]# yum repolist
3.安装相关软件包
[root@localhost ~]# yum -y install httpd httpd-devel mod_dav_svn subversion mod_ssl httpd,mod_dav_svn,httpd-devel,mod_ssl支持WEB形式管理SVN subversion (SVN服务器)
4.查看是否安装了svn模块
[root@localhost ~]# ls /etc/httpd/modules/ | grep svn mod_authz_svn.so mod_dav_svn.so #查看svn版本: [root@localhost ~]# svn --version svn, version 1.6.11 (r934486) compiled Mar 6 2014, 10:49:10 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
5.svn服务器的配置:
新建一个目录用于存储SVN所有文件
[root@localhost ~]# mkdir /data/svn -p
新建一个版本仓库
[root@localhost ~]# svnadmin create /data/svn/ [root@localhost ~]# cd /data/svn/ [root@localhost svn]# ls conf db format hooks locks README.txt #更改/data/svn属主属组: [root@localhost svn]# chown -R apache.apache /data/svn/
6.配置subversion.conf
加载mod_dav_svn模块,一般apache2己正常加载这两个模块 apache需要加载mod_dav_svn模块。如果apache是按照与预设目录安装的,mod_dav_svn模块应该会安装在apache安装位置(默认路径是/etc/httpd/)的 modules子目录内。同时apache的配置文件httpd.conf(默认路径为etc/httpd/conf/)中已经使用LoadModule指令加载了该模块(如果没有,手动添加)注意这个指令必须出现在其它的Subversion相关指令之前。还要加载mod_authz_svn.so模块。
[root@localhost conf.d]# vim /etc/httpd/conf.d/subversion.conf LoadModule dav_svn_module modules/mod_dav_svn.so LoadModule authz_svn_module modules/mod_authz_svn.so <Location /svn-test> DAV svn # SVNParentPath /var/www/svn SVNPath /data/svn SVNListParentPath on # # Limit write permission to list of valid users. # <LimitExcept GET PROPFIND OPTIONS REPORT> # # Require SSL connection for password protection. # # SSLRequireSSL # AuthType Basic AuthName "svn for project" AuthUserFile /data/svn/passwdfile AuthzSVNAccessFile /data/svn/accessfile Require valid-user # </LimitExcept> </Location>
7.添加用户和密码:
[root@localhost conf.d]# htpasswd -c /data/svn/passwdfile kaibin New password: Re-type new password: Adding password for user kaibin [root@localhost conf.d]# htpasswd /data/svn/passwdfile zhangsan New password: Re-type new password: Adding password for user zhangsan
8.重启apache
[root@localhost ~]# /etc/init.d/httpd restart Stopping httpd: [ OK ] Starting httpd:
9、下面创建权限访问控制文件,可自行查看具体权限:
# vim /data/svn/accessfile [/] *=rw [groups] dev=kaibin test=zhangsan [svn-test:/] @test=r @dev=r [repos:/test] @test=rw *=
10.启动svn服务器
[root@localhost svn]# svnserve -d -r /data/svn
11.用客户端登陆:
12.svn常用命令
svn服务器地址:192.168.40.129
1.查看文件详情信息
[root@test ~]# svn info http://192.168.40.129/svn-test Path: svn-test URL: http://192.168.40.129/svn-test Repository Root: http://192.168.40.120/svn-test Repository UUID: ad541a1c-e001-4760-8689-1949c7d67214 Revision: 1 Node Kind: directory Last Changed Author: kaibin Last Changed Rev: 1 Last Changed Date: 2015-01-28 18:51:12 -0800 (Wed, 28 Jan 2015)
2.将文件checkout到本地/test
[root@test ~]# mkdir /test [root@test ~]# svn checkout http://192.168.40.129/svn-test /test/ A /test/新建文本文档.txt Checked out revision 1. [root@test ~]# cd /test/ [root@test test]# ls 新建文本文档.txt
3.将新建的文件提交到代码服务器上
[root@test test]# echo "This is a test" >> test.txt [root@test test]# ls test.txt 新建文本文档.txt [root@test test]# svn add test.txt A test.txt
4.将修改的文件提交到版本库
[root@test test]# svn commit -m "This is a renew" test2.txt Adding test2.txt Transmitting file data . Committed revision 2.
5.更新到某个版本
将hosts文件更新到版本4
[root@test svn-test]# svn update -r 4 hosts U hosts Updated to revision 4.
将所有文件更新到版本4
[root@test svn-test]# svn update At revision 4. [root@test svn-test]# svn -r 4 update At revision 4.
6.显示文件和子目录状态
[root@test ~]# svn status -v svn-test/ 4 4 kaibin svn-test 4 4 kaibin svn-test/hosts 4 1 kaibin svn-test/新建文本文档.txt [root@test ~]# cd svn-test/ [root@test svn-test]# svn status -v hosts 4 4 kaibin hosts
第一列保持相同,第二列显示工作版本号,第三列显示最后一次修改人和版本号.
7.查看日志
[root@test ~]# svn log svn-test/hosts ------------------------------------------------------------------------ r4 | kaibin | 2015-03-05 18:13:46 -0800 (Thu, 05 Mar 2015) | 1 line xiu gai hosts wen jian.. ------------------------------------------------------------------------ r3 | kaibin | 2015-03-05 17:20:38 -0800 (Thu, 05 Mar 2015) | 1 line This is a test2. ------------------------------------------------------------------------ r2 | kaibin | 2015-03-05 17:19:58 -0800 (Thu, 05 Mar 2015) | 1 line This is a test. ------------------------------------------------------------------------
8.比较版本之间的差异
[root@test ~]# svn diff -r 4:5 svn-test/hosts Index: svn-test/hosts =================================================================== --- svn-test/hosts (revision 4) +++ svn-test/hosts (revision 5) @@ -17,3 +17,4 @@ 192.168.40.145 test.server03 test.server03.com 192.168.40.145 test.server03 test.server03.com 192.168.40.145 test.server03 test.server03.com +192.168.40.148 test.server03 test.server03.com [root@test ~]# svn diff -r 2:5 svn-test/hosts Index: svn-test/hosts =================================================================== --- svn-test/hosts (revision 2) +++ svn-test/hosts (revision 5) @@ -6,3 +6,15 @@ 192.168.40.145 test.server03 test.server03.com 192.168.40.145 test.server03 test.server03.com 192.168.40.145 test.server03 test.server03.com +192.168.40.145 test.server03 test.server03.com +192.168.40.145 test.server03 test.server03.com +192.168.40.145 test.server03 test.server03.com +192.168.40.145 test.server03 test.server03.com +192.168.40.145 test.server03 test.server03.com +192.168.40.145 test.server03 test.server03.com +192.168.40.145 test.server03 test.server03.com +192.168.40.145 test.server03 test.server03.com +192.168.40.145 test.server03 test.server03.com +192.168.40.145 test.server03 test.server03.com +192.168.40.145 test.server03 test.server03.com +192.168.40.148 test.server03 test.server03.com
9.查看版本库下的文件和列表
[root@test ~]# svn list http://192.168.40.129/svn-test hosts 新建文本文档.txt