SVN服务端安装管理与客户端使用

一、svn服务端安装与管理

1、安装

[root@localhost ~]# yum install -y subversion

2、新建目录用于存储svn

[root@localhost /]# mkdir /svn

3、新建仓库

[root@localhost svn]# svnadmin create sadoc

4、配置svn服务配置文件svnserver.conf

[root@localhost svn]# cd sadoc/
[root@localhost sadoc]# ls
README.txt  conf  db  format  hooks  locks
[root@localhost sadoc]# cd conf/    
[root@localhost conf]# ls
authz  passwd  svnserve.conf
[root@localhost conf]# vim svnserve.conf
### This file controls the configuration of the svnserve daemon, if you
### use it to allow access to this repository. (If you only allow
### access through http: and/or file: URLs, then this file is
### irrelevant.)

### Visit http://subversion.tigris.org/ for more information.

[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 = read  ##注意前边不要有空格,要顶齐
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
View Code

5、配置访问用户及密码

[root@localhost conf]# vim 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]
# harry = harryssecret
# sally = sallyssecret
lqb = lqb123456
test1 = 123456
test2 = 654321
View Code

6、配置新用户的授权文件

[root@localhost conf]# vim 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
# [/foo/bar]
# harry = rw
# &joe = r
# * =
# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r
admin = lqb,test2
user = test1
[/svn/test/]
@admin = rw 
@user = r
* =
View Code

  备注

  admin = lqb,test2   创建admin组,组成员为:lqb,test2

  user = test1      创建用户组,用户成员:test1 

  [test:/]       赋予根权限,为了便于管理和权限的控制,可以把权限细化到版本库中相应的目录

  @admin = rw       admin组有读写的权限

  @user = r        user组只有读的权限

  *   =            表示除了上面设置的权限用户组以外,其他所有用户都设置空权限,空权限表示禁止访问本目录,这很重要一定要加上。

7、启动svn服务

[root@localhost conf]#svnserve -d -r /svn/

二、svn客户端使用

 将文件checkout到本地目录

svn checkout path(path是服务器上的目录)
svn checkout svn://192.168.1.1/pro/domain
svn co

往版本库中添加新的文件

svn add file
svn add test.php(添加test.php)
svn add *.php(添加当前目录下所有的php文件)
svn add *.php --force(增加所有文件)

将改动的文件提交到版本库

svn commit -m “LogMessage“ [-N] [--no-unlock] PATH(如果选择了保持锁,就使用–no-unlock开关)
svn commit -m “add test file for my test“ test.php
svn ci

加锁/解锁

svn lock -m “LockMessage“ [--force] PATH
svn lock -m “lock test file“ test.php
svn unlock PATH

更新到某个版本

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

查看文件或者目录状态

svn status path(目录下的文件和子目录的状态,正常状态不显示)
【?:不在svn的控制中;M:内容被修改;C:发生冲突;A:预定加入到版本库;K:被锁定】

svn status -v path(显示文件和子目录状态)
第一列保持相同,第二列显示工作版本号,第三和第四列显示最后一次修改的版本号和修改人。

  注:svn status、svn diff和 svn revert这三条命令在没有网络的情况下也可以执行的,原因是svn在本地的.svn中保留了本地版本的原始拷贝。

svn st

删除文件

svn delete path -m “delete test fle“
svn delete svn://192.168.1.1/pro/domain/test.php -m “delete test file”
或者直接svn delete test.php 然后再svn ci -m ‘delete test file‘,推荐使用这种
svn (del, remove, rm) 

查看日志

svn log path 
svn log test.php 显示这个文件的所有修改记录,及其版本号的变化

查看文件详细信息

svn info path
svn info test.php

比较差异

svn diff path(将修改的文件与基础版本比较)
svn diff test.php
svn diff -r m:n path(对版本m和版本n比较差异)
svn diff -r 200:201 test.php
svn di

将两个版本之间的差异合并到当前文件

svn merge -r m:n path
svn merge -r 200:205 test.php(将版本200与205之间的差异合并到当前文件,但是一般都会产生冲突,需要处理一下)

SVN 帮助

svn help
svn help ci

版本库下的文件和目录列表

svn list path 
svn ls

创建纳入版本控制下的新目录

svn mkdir: 创建纳入版本控制下的新目录。
mkdir PATH…
mkdir URL…

创建版本控制的目录。
1、每一个以工作副本 PATH 指定的目录,都会创建在本地端,并且加入新增调度,以待下一次的提交。
2、每个以URL指定的目录,都会透过立即提交于仓库中创建.在这两个情况下,所有的中间目录都必须事先存在。

恢复本地修改

svn revert: 恢复原始未改变的工作副本文件 (恢复大部份的本地修改)。revert:
用法: revert PATH…
注意: 本子命令不会存取网络,并且会解除冲突的状况。但是它不会恢复被删除的目录

代码库URL变更

svn switch (sw): 更新工作副本至不同的URL。 

1switch URL [PATH]
2switch –relocate FROM TO [PATH...]
1、更新你的工作副本,映射到一个新的URL,其行为跟“svn update”很像,也会将服务器上文件与本地文件合并。这是将工作副本对应到同一仓库中某个分支或者标记的方法。

2、改写工作副本的URL元数据,以反映单纯的URL上的改变。当仓库的根URL变动(比如方案名或是主机名称变动),但是工作副本仍旧对映到同一仓库的同一目录时使用这个命令更新工作副本与仓库的对应关系。

解决冲突

svn resolved: 移除工作副本的目录或文件的“冲突”状态。 java设计模式之——策略模式
用法: resolved PATH…
注意: 本子命令不会依语法来解决冲突或是移除冲突标记;它只是移除冲突的相关文件,然后让 PATH 可以再次提交。

输出指定文件或URL的内容。

svn cat 目标[@版本]…如果指定了版本,将从指定的版本开始查找。 svn cat -r PREV filename > filename (PREV 是上一版本,也可以写具体版本号,这样输出结果是可以提交的

 

 

 

posted @ 2017-10-13 10:23  Jadear  阅读(281)  评论(0编辑  收藏  举报