svn1.6在centos6下的使用

版本

CentOS 6;svn 1.6.11
svn1.6版本的不足在于,每个目录递归存在.svn目录;从1.7开始就只有root节点目录存在.svn目录,和git一样了。
但是因为还在用CentOS6,又不想手动编译安装,先缓缓。

常用命令

初始代码下载到本地

svn co http://<your_svn_repo> .

新添加文件

svn add new_file

新添加目录,递归添加

svn add new_folder --force

删除文件
可以用delete、remove或者rm关键字

svn delete old_file

删除目录
这和和删除文件一样的,只不过删除文件是立即“删除”,删掉就看不到了;删除目录和目录下的文件,则需要commit后才能看到效果,所以推荐用一行命令搞定:

svn delete folder -m "delete redundant folder"

重命名

svn move src_file dst_file

解决冲突

svn resolved conflict_file  #表示“我解决了冲突”

忽略文件(夹)

svn propedit svn:ignore dir

其中dir表示指定的目录。输入完这条命令会进入编辑器的编辑界面编写ignore的规则,可以使用通配符*。
例如ecshop等cms有缓存目录,应当将缓存目录纳入svn管理,但缓存目录下的缓存文件应当忽略。因此可以先将整个项目add进来,然后将缓存目录revert,再指定仅add缓存目录一层:

#假设缓存目录为temp/caches temp/compiled/ temp/static temp/static_caches temp/auth
svn co http://some_site.com/svn/ecshop .
svn add . --force   
svn revert --recursive temp
svn add --non-recursive temp
svn add --non-recursive temp/caches
svn add --non-recursive temp/compiled
svn add --non-recursive temp/static
svn add --non-recursive temp/static_caches
svn add --non-recursive temp/auth

svn propedit svn:ignore temp   #输入*
svn propedit svn:ignore temp/auth   #输入*
svn propedit svn:ignore temp/caches   #输入*
svn propedit svn:ignore temp/compiled   #输入*
svn propedit svn:ignore temp/static   #输入*
svn propedit svn:ignore temp/static_caches   #输入*

回到某版本

# 将当前本地repo下代码,回滚到200版本
svn up -r 200 .

查看日志

svn log

查看文件详细信息

svn info some_file.php

命令缩写

svn up   =   svn update
svn co   =   svn checkout
svn st   =   svn status
svn ps   =   svn propset
svn ci   =   svn commit

命令范围

在某个子目录下,执行的命令一般是针对子目录下的目录和文件的。比如你的目录为:

foo
    bar
    test

如果你修改了bar和test两个目录下的内容,但处于bar目录,svn st得到的是bar目录下的状态信息,即:

cd bar
svn st

其他问题

这里只考虑apache http服务器和svn的集成

post-commit脚本

your_repo_path/hooks/post-commit.tmpl复制一份为post-commit,加可执行权限,用户和组为apache:

chmod +x post-commit
chown apache:apache post-commit

由于post-commit脚本是apache用户执行的,如果线上代码被root执行过svn update,就会使.svn目录的用户权限和用户组权限变掉,导致post-commit无法正确执行(可以通过post-commit脚本中打印日志查看),因此对于用ftp上传到线上、用户手动上传资源的情况,暂时编写了一个脚本,用于从线上commit并把权限改回来:

util_commit:

#!/bin/bash  
svn cleanup  
svn commit  
chown -R apache:apache .  

我的post-commit脚本也可以作为参考:

REPOS="$1"  
REV="$2"  
	
export LANG=zh_CN.UTF-8  
	
SVN_PATH=/usr/bin/svn  
WEB_PATH=/var/www/html/xxx.yyy.com  
TEMP_PATH=/var/www/html/xxx.yyy.com/temp  
  
CURDATE=`date`  
  
LOG_PATH=/tmp/svn_some_update.log  
echo "   "  
echo "---code deployed at $CURDATE---" >> $LOG_PATH 2>&1  
echo `whoami`,$REPOS,$REV >> $LOG_PATH  
/usr/bin/svn update --username username --password password $WEB_PATH --no-auth-cache >> $LOG_PATH 2>&1  
echo "---code deployed end---"    

记得把上面username和password替换掉

svn post commit产生的日志乱码

在vim中配置:

set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8	
set encoding=utf-8

然后再去看日志文件

Write lock stolen

这个问题发生在svn delete xxx时.解决办法是:

touch xxx
svn revert xxx
rm xxx
posted @ 2015-10-17 13:35  ChrisZZ  阅读(850)  评论(0编辑  收藏  举报