SVN一些用法整理

在做源码版本管理的时候,有时整个大版本的升级,会替换很多文件,也会新增很多文件,我们需要在升级完成之后对整个网站加入版本管理。

1.对更新删除导致丢失的文件进行批量删除

#svn status | awk '{if($1 == "!"){print $2}}' | xargs -r svn delete

原理是通过查询当前文件夹的文件状态,用awk进行分割获取到!标记的文件名称,附加给xargs 分别执行svn delete 操作。
如果中途遇到报错,可以多运行几次,有些文件可能已经丢失了。

2.对新增的文件进行批量新增

#svn status | awk '{if($1 == "?"){print $2}}' | xargs -r svn add

这个语句的原理和上一条删除是一样的,只是针对文件的状态标记进行筛选操作。

3.对新增或者修改的文件进行批量提交入库

#svn status | awk '{if($1 == "M" || $1 == "A"){print $2}}' | xargs -r svn commit -m "这里是备注"

同样的方法,只是在提交入库的时候需要提交备注名称,不然会报错。使用-m参数加上备注内容即可,比如备注“将wordpress从5.0.1更新到5.0.2版本”,方便下次查看回滚版本。

4.查看当前目录版本控制的文件和目录列表

#svn list

5.查看当前文件夹的版本控制情况

#svn status

windows状态图标覆盖问题

最近这段时间开始使用 microsoft 的 onedrive,刚开始重装完系统的时候更新了软件,发现同步的文件夹是有状态图标的,如下图:

但是因为最近要做一个项目,所以下载了SVN版本控制,当我安装完svn之后是可以正常显示图标状态的,该正常更新的更新,该添加的显示添加。直到今天早上开机,当我点开onedrive的时候,发现状态图标不显示了。有状态到无状态是很难受的,后来网上搜索,发现是因为windows下的软件共用图标位置数量问题。

现在我默认把360的一个优盘图标改名到底部,然后将腾讯微云的图标也改到底部去,剩下svn和onedrive的图标就可以正常显示了。

系统默认只显示11个图标位置,在注册表可以调整顺序,从上到下的顺序优先:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers]

CentOS配置svn服务

一、安装subversion

安装subversion服务软件

#yum install subversion

查看安装后文件的分布情况

#rpm -ql subversion

卸载subversion

#yum remove subversion

停止subversion服务

#killall svnserve

二、创建仓库

以创建多个仓库为例

#svnadmin create /var/svn/demo
#svnadmin create /var/svn/test

/var/svn/demo和/var/svn/test为所创建两个新仓库的路径,理论上可以是任何目录。这里我取/var/svn为所有仓库的根路径,在目录下面分别创建仓库。

三、配置仓库

针对每个仓库单独配置,分别修改每个仓库conf目录下的三个配置文件(authz、passwd、svnserve.conf)

1.修改authz文件,这个配置文件里面可以设置用户组和用户目录权限

#vim /var/svn/demo/conf/authz
### This file is an example authorization file for svnserve.
### Its format is identical to that of mod_authz_svn authorization
### files.
### As shown below each section defines authorizations for the path and
### (optional) repository specified by the section name.
### The authorizations follow. An authorization line can refer to:
###  - a single user,
###  - a group of users defined in a special [groups] section,
###  - an alias defined in a special [aliases] section,
###  - all authenticated users, using the '$authenticated' token,
###  - only anonymous users, using the '$anonymous' token,
###  - anyone, using the '*' wildcard.
###
### A match can be inverted by prefixing the rule with '~'. Rules can
### grant read ('r') access, read-write ('rw') access, or no access
### ('').

[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average

[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
admin = admin,user1,user2
# [/foo/bar]
# harry = rw
# &joe = r
# * =

# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r
[/]
@admin 	= rw
*	=

上面加粗部分是我配置的内容,第一部分配置一个用户组admin 有成员admin和user1、user2三个;第二部分配置目录权限,设置admin组(前面加@符号)的权限为读写权限,其他成员没有权限(* = )

2.修改passwd文件,设置访问当前仓库的用户和密码

#vim /var/svn/demo/conf/passwd
passwd文件配置

3.修改svnserve.conf文件,开启权限控制等功能

找到第一个常规选项[general],把前面是一个#号的去掉#号,如下是我的demo仓库配置内容

#vim /var/svn/demo/svnserve.conf
[general]
### These options control access to the repository for unauthenticated
### and authenticated users.  Valid values are "write", "read",
### and "none".  The sample settings below are the defaults.
anon-access = none
auth-access = write
### The password-db option controls the location of the password
### database file.  Unless you specify a path starting with a /,
### the file's location is relative to the directory containing
### this configuration file.
### If SASL is enabled (see below), this file will NOT be used.
### Uncomment the line below to use the default password file.
password-db = passwd
### The authz-db option controls the location of the authorization
### rules for path-based access control.  Unless you specify a path
### starting with a /, the file's location is relative to the the
### directory containing this file.  If you don't specify an
### authz-db, no path-based access control is done.
### Uncomment the line below to use the default authorization file.
authz-db = authz
### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa.  The default realm
### is repository's uuid.
realm = demo

注意:所有的行都必须顶格,否则报错。

备注:多个仓库使用同一套账号密码认证,可以通过修改各个仓库的配置文件svnserve.conf 来实现,将认证文件和密码账号文件指向同一个文件即可。

四、启动和关闭服务

1.启动服务

#svnserve -d -r /var/svn --listen-host
192.168.1.100

命令中/var/svn是我所有仓库的所在的根目录,如果单个仓库,可以直接写仓库地址即可,比如启动demo仓库,#svnserve -d -r /var/svn/demo –listen-host 192.168.1.100

2.停止服务

#killall svnserve

五、访问仓库项目

我们有两个代码仓库/var/svn/demo 和/var/svn/test,那么在客户端访问时可以用。

svn://192.168.1.100/demo
svn://192.168.1.100/test

六、开放服务器端口(可选)

svn默认端口是3690,如果你设置了防火墙,你需要在防火墙上开放这个端口,iptables如下配置:

#/sbin/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3690 -j ACCEPT
#/sbin/service iptables save

(完)