一、linux服务器端配置
[root@server ~]# rpm -qa | grep subsubversion-libs-1.7.14-10.el7.x86_64subversion-1.7.14-10.el7.x86_64[root@server ~]# ps -ef | grep svnroot 21019 20613 0 21:57 pts/0 00:00:00 grep --color=auto svn[root@server ~]# mkdir -p /opt/svn/repo[root@server ~]# svnserve --versionsvnserve, version 1.7.14 (r1542130) compiled Nov 20 2015, 19:25:09
Copyright (C) 2013 The Apache Software Foundation.This software consists of contributions made by many people; see the NOTICEfile for more information.Subversion is open source software, see http://subversion.apache.org/The following repository back-end (FS) modules are available:* fs_base : Module for working with a Berkeley DB repository.* fs_fs : Module for working with a plain file (FSFS) repository.Cyrus SASL authentication is available.[root@server ~]# svnadmin create /opt/svn/repo/[root@server ~]# cd /opt/svn/repo/[root@server repo]# pwd/opt/svn/repo[root@server repo]# lsconf db format hooks locks README.txt[root@server repo]# cd conf/[root@server conf]# pwd/opt/svn/repo/conf[root@server conf]# lsauthz passwd svnserve.conf[root@server conf]# vim authz 注:authz最后加上以下两行(这两行解决了 SVN客户端解决authorization failed问题)[/]* = rw[root@server conf]# vim passwd 注:passwd修改为:[users] admin = 123456 //这里的username和password自己设置 [root@server conf]# vim svnserve.conf 注:配置如下:anon-access = none #匿名访问的权限,可以是read,write,none,默认为readauth-access = write #使授权用户有写权限password-db = passwd #密码数据库的路径 authz-db = authz #访问控制文件 realm = /opt/svn/repo #认证命名空间,subversion会在认证提示里显示,并且作为凭证缓存 #的关键字[root@server conf]# cd[root@server ~]# svnserve -d -r /opt/svn/-d 表示后台运行 -r 指定根目录是 /opt/svn/[root@server ~]# ps -ef | grep svnroot 21122 1 0 22:21 ? 00:00:00 svnserve -d -r /opt/svn/root 21124 20613 0 22:21 pts/0 00:00:00 grep --color=auto svn[root@server ~]# netstat -antlp | grep svntcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 21122/svnserve
二、linux客户端使用介绍
1、将文件checkout到本地目录
[root@server home]# cd[root@server ~]# cd /home/[root@server home]# ls[root@server home]# svn checkout svn://127.0.0.1/repo #简写:svn co Checked out revision 0.[root@server home]# lsrepo
2、往版本库中添加新的文件
[root@server home]# cd repo/[root@server repo]# ls[root@server repo]# touch test.txt[root@server repo]# lstest.txt[root@server repo]# svn add test.txt A test.txt
3、将改动的文件提交到版本库
svn commit -m “LogMessage“ [-N] [--no-unlock] PATH(如果选择了保持锁,就使用–no-unlock开关) [root@server repo]# svn commit -m "add testing" test.txt #简写:svn ci Adding test.txtTransmitting file data .Committed revision 1.[root@server repo]# lstest.txt[root@server repo]# vim test.txt [root@server repo]# cat test.txt testingtestingtestingtestingtestingtestingtestingtesting[root@server repo]# svn commit -m "add testing something" test.txt Sending test.txtTransmitting file data .Committed revision 2.
4、删除文件
svn delete path -m “delete test fle“
例如:第一步:svn delete svn://192.168.10.151/pro/domain/test.php -m “delete test file”
第二步:svn commit
第三步:svn update
或者直接svn delete test.php 然后再svn ci -m ‘delete test file‘,推荐使用这种
简写:svn (del, remove, rm)
5、更新到某个版本
svn update -r m path
例如:
svn update如果后面没有目录,默认将当前目录以及子目录下的所有文件都更新到最新版本。
svn update -r 200 test.php(将版本库中的文件test.php还原到版本200)
svn update test.php(更新,于版本库同步。如果在提交的时候提示过期的话,是因为冲突,需要先update,修改文件,然后清除svn resolved,最后再提交commit)
简写:svn up
6、恢复本地修改
svn revert: 恢复原始未改变的工作副本文件 (恢复大部份的本地修改)。revert:
用法: revert PATH…
注意: 本子命令不会存取网络,并且会解除冲突的状况。但是它不会恢复
被删除的目录
7、解决冲突
svn resolved: 移除工作副本的目录或文件的“冲突”状态。
用法: resolved PATH…
注意: 本子命令不会依语法来解决冲突或是移除冲突标记;它只是移除冲突的
相关文件,然后让 PATH 可以再次提交。
8、加锁/解锁
svn lock -m “LockMessage“ [--force] PATH
例如:svn lock -m “lock test file“ test.php
svn unlock PATH
9、查看文件或者目录状态
1)svn status path(目录下的文件和子目录的状态,正常状态不显示)
【?:不在svn的控制中;M:内容被修改;C:发生冲突;A:预定加入到版本库;K:被锁定】
2)svn status -v path(显示文件和子目录状态)
第一列保持相同,第二列显示工作版本号,第三和第四列显示最后一次修改的版本号和修改人。
注:svn status、svn diff和 svn revert这三条命令在没有网络的情况下也可以执行的,原因是svn在本地的.svn中保留了本地版本的原始拷贝。
简写:svn st
10、查看日志
svn log path
例如:svn log test.php 显示这个文件的所有修改记录,及其版本号的变化
11、查看文件详细信息
svn info path
例如:svn info test.php
12、比较差异
svn diff path(将修改的文件与基础版本比较)
例如:svn diff test.php
svn diff -r m:n path(对版本m和版本n比较差异)
例如:svn diff -r 200:201 test.php
简写:svn di
13、将两个版本之间的差异合并到当前文件
svn merge -r m:n path
例如:svn merge -r 200:205 test.php(将版本200与205之间的差异合并到当前文件,但是一般都会产生冲突,需要处理一下)
14、SVN 帮助
svn help
svn help ci
三、自动更新项目文件到web发布目录(www)
1、检出(checkout)到本地目录是/home/repo
[root@server repo]# lsindex.php test.txt[root@server repo]# cd ..[root@server home]# lsrepo[root@server home]# mv repo/ www/ #将检出到本地的版本目录更名为web发布目录[root@server home]# lswww[root@server home]# cd www/[root@server www]# lsindex.php test.txt
2、通过脚本文件实现自动更新
使用SVN中post-commit实现自动实时从svn中检出文件并同步到Web站点根目录
[root@server ~]# cd /opt/svn/repo/[root@server repo]# lsconf db format hooks locks README.txt[root@server repo]# cd hooks/[root@server hooks]# pwd/opt/svn/repo/hooks[root@server hooks]# lspost-commit.tmpl post-unlock.tmpl pre-revprop-change.tmplpost-lock.tmpl pre-commit.tmpl pre-unlock.tmplpost-revprop-change.tmpl pre-lock.tmpl start-commit.tmpl[root@server hooks]# cp post-commit.tmpl post-commit[root@server hooks]# lspost-commit post-revprop-change.tmpl pre-lock.tmpl start-commit.tmplpost-commit.tmpl post-unlock.tmpl pre-revprop-change.tmplpost-lock.tmpl pre-commit.tmpl pre-unlock.tmpl[root@server hooks]# cp post-commit.tmpl post-commit[root@server hooks]# vim post-commit[root@server hooks]# > post-commit[root@server hooks]# vim post-commit
******************************************************************************************
输入:#!/bin/shexport LC_CTYPE="zh_CN.UTF-8"SVN=/usr/bin/svnWEB_PATH=/home/www #要强制更新的目录SVN_USER=adminSVN_PASS=123456$SVN update $WEB_PATH --username $SVN_USER --password $SVN_PASS #执行更新
******************************************************************************************
[root@server hooks]# ll post-commit-rw-r--r--. 1 root root 220 Apr 13 00:21 post-commit[root@server hooks]# chmod a+x post-commit #给予执行权限[root@server hooks]# ll post-commit-rwxr-xr-x. 1 root root 220 Apr 13 00:21 post-commit[root@server hooks]# cat post-commit#!/bin/shexport LC_CTYPE="zh_CN.UTF-8"SVN=/usr/bin/svnWEB_PATH=/home/www #要强制更新的目录SVN_USER=adminSVN_PASS=123456$SVN update $WEB_PATH --username $SVN_USER --password $SVN_PASS #执行更新[root@server hooks]# pwd/opt/svn/repo/hooks
注:文件/opt/svn/repo/hooks(俗称钩子)/post-commit属于自动执行。