Subversion基本操作

本文详细介绍如何使用Subversion进行版本控制,包括服务器搭建、版本库创建、数据导入、本地副本检出及版本控制操作。通过实际案例,展示如何利用Subversion进行文件的增删改查、提交、更新及权限设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Subversion基本操作

问题

本案例要求先快速搭建好一台Subversion服务器,并测试该版本控制软件:
1)创建版本库
2)导入初始化数据
3)检出数据至用户本地副本
4)对本地副本进行增删改查等操作

方案

使用RPM安装subversion软件,使用svn客户端工具连接svnserver服务器并测试版本控制软件。
使用svn命令测试svnserver服务时可以使用的命令列表如表-1所示。
表-1 svn命令列表

命令作用
add添加文件
commit提交更新
checkout检出代码
cat查看代码文件内容
del删除文件
diff文件对比
import导入代码
info查看版本信息
list查看文件列表
log查看版本历史
update更新
mkdir创建目录

步骤

实现此案例需要按照如下步骤进行。
步骤一:安装Subversion服务器
1)YUM安装subversion软件

[root@svr5 ~]# yum -y install subversion
[root@svr5 ~]# rpm -q subversion

2)创建版本库

[root@svr5 ~]# mkdir /var/svn/ 
[root@svr5 ~]# svnadmin create /var/svn/project
[root@svr5 ~]# ls /var/svn/project/
conf/  db/  format  hooks/  locks/  README.txt

3)修改配置文件,创建账户与密码

[root@svr5 ~]# vim /var/svn/project/conf/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 = 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		//ACL访问控制列表文件
### 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
[root@srv5 ~]# vim /var/svn/project/conf/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 = pass			//用户名和密码
tom= pass				//用户名和密码
[root@svr5 ~]# cat /var/svn/project/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_tom = harry,tom			//定义组账户,组成员为harry和tom

# [/foo/bar]
# harry = rw
# &joe = r
# * =

[/]								//定义ACL访问控制
@harry_and_sally = rw				//harry_and_sally组成员对项目可读可写
* = r							//其他人只读

4)启动服务

[root@svr5 ~]# service svnserve start
[root@svr5 ~]# netstat -nutlp |grep svnserve
tcp        0      0 0.0.0.0:3690	0.0.0.0:*	LISTEN      4043/svnserve    

步骤二:客户端测试
1)本地导入初始化数据

[root@srv5 ~]# mkdir /myscripts
[root@srv5 ~]# cp /etc/rc.d/init.d/* /myscripts/	//将启动脚本及个人自定义脚本汇总,如果有其他脚本,则一并复制至此
[root@srv5 ~]# svn import /myscripts/ file:///var/svn/project/ -m "Init Data"
[root@srv5 ~]# cd /var/tmp
[root@srv5 ~]# svn --username harry --password pass \
co svn://127.0.0.1/var/svn/project harry		//harry账户检查数据,建立本地副本

-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:

   <svn://127.0.0.1:3690> b72f45f0-bbe5-4a0c-ad4a-37f52704f0b1

can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation

 for details.

You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/root/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? yes			//提示是否保存密码
A    harry/netfs
A    harry/kdump
A    harry/acpid
A    harry/blk-availability
A    harry/killall
A    harry/NetworkManager
A    harry/quota_nld
A    harry/udev-post
A    harry/haldaemon
A    harry/saslauthd
A    harry/network
vim test.sh
[root@srv5 ~]# cd /var/tmp/harry
[root@srv5 harry]# ls
[root@srv5 harry]# vim test.sh 			//新建脚本文件
#!/bin/bash
case $1 in
start)
	echo start;;
stop)
	echo stop;;
*)
	echo Error
esac
[root@srv5 harry]# chmod +x test.sh
[root@srv5 harry]# svn add test.sh			//将文件或目录加入版本控制
[root@srv5 harry]# svn mkdir subdir		//创建子目录
[root@srv5 harry]# svn status				//检查状态,结果为两个添加append
A       test.sh
A       subdir
[root@srv5 harry]# svn del cups			//删除版本库中的文件
[root@srv5 harry]# svn move test.sh test	//脚本重命名
A         test
D         test.sh
[root@srv5 harry]# svn commit -m "add a file and subdir,remove cups file"	
											//将本地副本的修改提交版本库
Deleting       cups
Adding         subdir
Adding         test
Transmitting file data .
Committed revision 2.
[root@srv5 harry]# sed -i '1a##test###' halt	//修改本地副本中的代码文件
[root@srv5 harry]# sed -i '2a###test###' killall
[root@srv5 harry]# svn diff killall			//查看单个文件本地副本与版本库的差异
[root@srv5 harry]# svn diff					//查看所有本地副本与版本库的差异
[root@srv5 harry]# svn log svn://127.0.0.1/var/svn/project	//查看修改历史
[root@srv5 harry]# svn update				//更新本地副本文件,从版本库下载更新数据
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值