SVN服务端的搭建
CentOS 7 安装SVN服务器端程序
安装命令
yum install -y subversion
验证
svn --version
创建并配置版本库
创建版本库目录
mkdir -p /var/svn/repository
在版本库目录下创建具体项目目录
mkdir helloworld
创建SVN版本库
svnadmin create /var/svn/repository/helloworld
查看效果
conf:是这个仓库的配置文件(仓库的用户访问账号、权限等)db:是所有版本控制的数据存放文件hooks:放置hook脚本文件的目录locks:用来放置subversion见艰苦锁定数据的目录,用来追踪存取文件库的客户端
配置SVN的服务
SVN默认的端口是 3690
客户端请求服务器端的 helloworld 项目的URL地址:svn://ip:3690/helloworld
修改服务的配置(将我们创建的版本库交给SVN服务管理)
vim /etc/sysconfig/svnserve
修改路径为你之前创建的版本库根目录
启动SVN的服务
查看SVN服务
systemctl list-unit-files | grep svn
设置开机自启
systemctl enable svnserve.service
启动服务
systemctl start svnserve.service
验证服务是否启动成功
SVN的权限管理
在服务器端的版本库配置文件夹下有三个配置文件
authz :分配权限的配置文件
[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average
# 用户组
[groups]
chengdu = user1,user2
beijing = user3
# 针对版本库根目录设置权限
[/]
@beijing = rw
# 设置指定版本库权限
[/helloworld]
@chengdu = rw
user5 = r
# * = 表示除了上述配置权限的用户之外,其他用户没有任何权限
* =
passwd :设置用户名密码的配置文件
### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.
[users]
user1 = passwd01
user2 = 123456
user3 = abcdefg
user4 = aaaa
user5 = bbbb
svnserve.conf :版本库服务配置文件
### Visit http://subversion.apache.org/ for more information.
[general]
### The anon-access and auth-access options control access to the
### repository for unauthenticated (a.k.a. anonymous) users and
### authenticated users, respectively.
### Valid values are "write", "read", and "none".
### Setting the value to "none" prohibits both reading and writing;
### "read" allows read-only access, and "write" allows complete
### read/write access to the repository.
### The sample settings below are the defaults and specify that anonymous
### users have read-only access to the repository, while authenticated
### users have read and write access to the repository.
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 = My First Repository
### The force-username-case option causes svnserve to case-normalize
### usernames before comparing them against the authorization rules in the
### authz-db file configured above. Valid values are "upper" (to upper-
### case the usernames), "lower" (to lowercase the usernames), and
### "none" (to compare usernames as-is without case conversion, which
### is the default behavior).
# force-username-case = none
[sasl]
### This option specifies whether you want to use the Cyrus SASL
### library for authentication. Default is false.
### This section will be ignored if svnserve is not built with Cyrus
### SASL support; to check, run 'svnserve --version' and look for a line
### reading 'Cyrus SASL authentication is available.'
# use-sasl = true
### These options specify the desired strength of the security layer
### that you want SASL to provide. 0 means no encryption, 1 means
### integrity-checking only, values larger than 1 are correlated
### to the effective key length for encryption (e.g. 128 means 128-bit
### encryption). The values below are the defaults.
# min-encryption = 0
# max-encryption = 256
33,1 Bot
命令行客户端操作SVN
检出 checkout|co
用来完整下载版本库中的全部内容。
svn co svn://47.106.183.193/helloworld ./
# svn在检出的时候可以指定用户名和密码
svn co svn://47.106.183.193/helloworld --username xxx --password yyy ./
工作副本
-
.svn所在的目录,对于上面示例而言,user1这个目录就是工作副本 -
版本控制相关操作都需要在工作副本目录下执行。例如:提交、更新等等
这样的操作
-
为了保证工作副本能够正常和服务器进行交互,请不要删除或修改.svn目
录中的内容
添加 add
SVN要求提交一个新建的文件前先把这个文件添加到版本控制体系中
svn add hello.txt
此时 hello.txt 的状态为 A ,意味着这个文件已经被成功地添加到了版本控制中。如果状态为 ? ,则说明它还未加到版本控制中。
提交 commit|ci
要求1:附加日志信息
- 日志信息相当于写Java代码时的注释,用来标记本次操作所做的修改
- svn commit -m "xxx" [文件名]
要求2:必须具备相应的权限
修改服务器的版本库的配置文件 /conf/svnserve.conf ,把匿名访问配置项的注释打开
svn ci -m "第一次提交" hello.txt
提交完之后,版本号自动增加了1。
显示版本的所有信息 log
用来展示svn 的版本作者、日期、路径等等,如果只希望查看特定的某两个版本之间的信息,可以携带 -r 开始版本:结束版本 参数
svn log
svn log -r 开始版本号:结束版本号
查看 list
查看SVN版本库的内容
svn list svn://47.106.183.193/helloworld
更新 update|up
把服务器端文件所产生的所有修改下载到本地
svn up
回退版本 revert
还未提交
当我们想放弃对文件的修改,可以使用 svn revert 命令,将撤销任何文件或目录里的局部更改,revert 操作不单单可以使单个文件恢复原状, 而且可以使整个目录恢复原状。恢复目录需要携带 -R 参数
svn revert 文件名
svn revert -R 目录名
已经提交
对于已经提交的修改,我们需要使用 merge 命令进行回退,同时需要携带 -r 参数
svn merge -r 最新版本号:目标版本号 目录名或文件名
冲突
过时的文件
在一个相对服务器端版本来说是旧版本的基础上进行了修改的文件,这时候如果提交则会失败!
所有过时的文件都必须先执行更新操作,更新后在最新版基础上修改的文件才允许提交。
更新完之后,user1对文件的修改也同步到了user2的工作副本,之后user2就可以正常提交了
冲突的产生
从服务器端更新下来的修改和本地的修改在“同文件同位置”不一致,也就是修改了同一行内容
现在两个用户同时修改了同一行,user2先提交了,这时user1更新时发现冲突
冲突的表现
文件内部
<<<<<<<到|||||||是本地修改之后的内容|||||||到=======是修改之前的内容=======到>>>>>>>是服务器端修改的内容
目录内部
由于发生冲突会产生以下三个文件
-
xxx.mine文件:发生冲突时本地文件内容 -
xxx.r[小版本号]文件:发生冲突前文件内容 -
xxx.r[大版本号]文件:发生冲突时服务器端文件内容
手动解决冲突
- 删除冲突发生时产生的三个多余文件
- 删除冲突文件内多余的符号
- 把文件编辑到满意的状态
- 提交
半自动解决冲突
(p):推迟,之后手动处理(df):显示全部差异(e):编辑(m):合并(s):显示全部选项
# 跳过此冲突,稍后解决[推迟]
(p) - skip this conflict and leave it unresolved [postpone]
# 接受整个文件的传入版本[使用版本库里的文件]
(tf) - accept incoming version of entire file [theirs-full]
# 拒绝此文件的所有传入更改[使用我自己的文件]
(mf) - reject all incoming changes for this file [mine-full]
# 只接受冲突的传入更改
(tc) - accept incoming changes only where they conflict [theirs-conflict]
# 拒绝冲突的传入更改并接受其余更改
(mc) - reject incoming changes which conflict and accept the rest [mine-conflict]
# 接受工作副本中显示的文件
(r) - accept the file as it appears in the working copy [working]
# 推迟所有剩余冲突
(q) - postpone all remaining conflicts
# 在编辑器中更改合并文件
(e) - change merged file in an editor [edit]
# 显示对合并文件所做的所有更改
(df) - show all changes made to merged file
# 显示所有冲突(忽略合并版本)
(dc) - show all conflicts (ignoring merged version)
# 使用合并工具解决冲突
(m) - use merge tool to resolve conflict
# 启动外部合并工具以解决冲突[启动]
(l) - launch external merge tool to resolve conflict [launch]
# 使用内置的合并工具解决冲突
(i) - use built-in merge tool to resolve conflict
按下 e 进行编辑页面
之后就是和上面一样的步骤,删除掉特殊符号,然后把文件编辑到满意的状态,之后保存退出
按下 r 标记为已解决,之后就可以再次提交了
避免冲突
- 尽可能在修改文件前先进行更新操作,尽量在最新版基础上修改文件内容
- 尽量减少多人修改同一个文件的可能性
- 加强团队成员之间的沟通