linux: 安装svn和svn命令大全

1. 安装SVN

[root@Server ~]# yum -y install subversion            //使用YUM安装SVN
Last metadata expiration check: 0:17:56 ago on Wed 25 Sep 2019 04:49:06 PM CST.
Dependencies resolved.
(中间省略……)
Verifying        : apr-util-openssl-1.6.1-6.el8.x86_64                      4/8
  Verifying        : libserf-1.3.9-8.module_el8.0.0+45+75bba4f4.x86_64      5/8
  Verifying        : subversion-1.10.2-1.module_el8.0.0+45+75bba4f4.x86_64  6/8
  Verifying        : subversion-libs-1.10.2-1.module_el8.0.0+45+75bba4f4.x86_64 7/8
  Verifying        : utf8proc-2.1.1-4.module_el8.0.0+45+75bba4f4.x86_64     8/8

Installed:
  subversion-1.10.2-1.module_el8.0.0+45+75bba4f4.x86_64  apr-util-bdb-1.6.1-6.el8.x86_64                             apr-util-openssl-1.6.1-6.el8.x86_64                 apr-1.6.3-9.el8.x86_64  apr-util-1.6.1-6.el8.x86_64
  libserf-1.3.9-8.module_el8.0.0+45+75bba4f4.x86_64      subversion-libs-1.10.2-1.module_el8.0.0+45+75bba4f4.x86_64  utf8proc-2.1.1-4.module_el8.0.0+45+75bba4f4.x86_64

Complete!

2. 创建SVN库

[root@Server ~]# mkdir /usr/local/svn            //创建SVN目录
[root@Server ~]# svnserve -d -r /usr/local/svn
[root@Server ~]# svnadmin create /usr/local/svn/01-test
[root@Server ~]# ls /usr/local/svn/
01-test
[root@Server ~]# ls /usr/local/svn/01-test
conf  db  format  hooks  locks  README.txt

3. 配置SVN

[root@Server ~]# mkdir /usr/local/svn/Conf
[root@Server ~]# cp /usr/local/svn/01-test/conf/* /usr/local/svn/Conf/
[root@Server ~]# cd /usr/local/svn/Conf/
[root@Server Conf]# ls
authz  passwd  svnserve.conf
[root@Server Conf]# vi 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

SuperAdmin = admin
Jacky.xi = admin,jacky.xi

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

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

[01-ProductManagement:/]
@SuperAdmin = rw

[02-ProductPrototype:/]
@SuperAdmin = rw

[03-AxureTeamProject:/]
@SuperAdmin = rw
[root@Server conf]# vi 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

admin = 1qaz@WSX
jacky.xing = jacky888
[root@Server Conf]# vi 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.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 = /usr/local/svn/Conf/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
### directory containing this file.  The specified path may be a
### repository relative URL (^/) or an absolute file:// URL to a text
### file in a Subversion repository.  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 = /usr/local/svn/Conf/authz
### The groups-db option controls the location of the file with the
### group definitions and allows maintaining groups separately from the
### authorization rules.  The groups-db file is of the same format as the
### authz-db file and should contain a single [groups] section with the
### group definitions.  If the option is enabled, the authz-db file cannot
### contain a [groups] section.  Unless you specify a path starting with
### a /, the file's location is relative to the directory containing this
### file.  The specified path may be a repository relative URL (^/) or an
### absolute file:// URL to a text file in a Subversion repository.
### This option is not being used by default.
# groups-db = groups
### 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 = svn
### 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
### The hooks-env options specifies a path to the hook script environment
### configuration file. This option overrides the per-repository default
### and can be used to configure the hook script environment for multiple
### repositories in a single file, if an absolute path is specified.
### Unless you specify an absolute path, the file's location is relative
### to the directory containing this file.
# hooks-env = hooks-env

[sasl]
### This option specifies whether you want to use the Cyrus SASL
### library for authentication. Default is false.
### Enabling this option requires svnserve to have been 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
[root@Server Conf]# cp svnserve.conf /usr/local/svn/01-test/conf/
cp: overwrite '/usr/local/svn/01-test/conf/svnserve.conf'? y

4. 启动SVN服务

[root@Server Conf]# vi /usr/lib/systemd/system/svnserve.service             //创建svnserve.service服务
[Unit]
Description=Subversion protocol daemon
After=syslog.target network.target
Documentation=man:svnserve(8)

[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/svnserve
#ExecStart=/usr/bin/svnserve --daemon --pid-file=/run/svnserve/svnserve.pid $OPTIONS
ExecStart=/usr/bin/svnserve --daemon $OPTIONS
PrivateTmp=yes

[Install]
WantedBy=multi-user.target
[root@Server Conf]# systemctl daemon-reload
[root@Server Conf]# vi /etc/sysconfig/svnserve

# OPTIONS is used to pass command-line arguments to svnserve.
#
# Specify the repository location in -r parameter:
OPTIONS="-r /usr/local/svn"
[root@Server Conf]# systemctl status svnserve.service               //查看SVN服务状态
● svnserve.service - Subversion protocol daemon
   Loaded: loaded (/usr/lib/systemd/system/svnserve.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:svnserve(8)
[root@Server Conf]# systemctl start svnserve.service           //启动SVN服务
[root@Server Conf]# systemctl enable svnserve.service          //设置SVN服务开机自启动
Created symlink /etc/systemd/system/multi-user.target.wants/svnserve.service → /usr/lib/systemd/system/svnserve.service.

大功告成检出我们创建好的仓库 :  svn co svn://172.19.33.55/01-test/

常用命令

svn启动服务 systemctl start svnserve.service

svn重启服务 systemctl restart svnserve.service

svn停止服务 systemctl stop svnserve.service

1、svn checkout path

path 是服务器上的目录。

svn checkout path
例如:svn checkout  svn://192.168.1.1/pro/domain
简写:svn co

1.1 svn checkout path subv

这样将把你的工作拷贝放到subv而不是和前面那样放到trunk

2、svn add file

file是某个文件或者某个目录,如果添加所有的文件则用点“.”表示。

svn add file
例如:svn add test.php
svn  add  *.php(添加当前目录下所有的php文件)
svn add . (表示添加所有文件)

3、svn commit

提交文件到服务器。

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

一般步骤:

  • step-1:svn update
  • step-2:svn add file、svn delete file
  • step-3:svn commit -m “提交文件到远程服务器”

4、svn lock

加锁/解锁命令。

svn lock -m “LockMessage” [--force] path
例如:svn lock -m “lock test file”  test.php
svn unlock path

5、svn update

更新版本命令。

svn update -r m path
例如:
1、	svn update 后面没有目录,默认更新当前目录及子目录的所有文件到最新版本。
2、	svn update -r 200 test.php (将版本库中的文件test.php还原到版本200)
简写:svn up

update命令还可以进行文件恢复。
(1)不小心写错了很多东西,想撤销所写的东西(已经把修改提交到服务器)
svn update -r 版本号
(2)不小心删错了文件,想把文件恢复回来(已经把删除提交到服务器)
svn update -r 版本号

6、svn status

svn status -v path
svn status path
简写:svn st

显示文件和子目录的状态。
第一列保持相同,第二列显示工作版本号,第三和第四列显示最后一次修改的版本号和修改人。
注:svn statussvn diff和 svn revert这三条命令在没有网络的情况下也可以执行的,原因是svn在本地的.svn中保留了本地版本的原始拷贝。

文件状态描述

  • A 被添加到本地代码仓库
  • ' ' 没有修改
  • C 冲突
  • D 被删除
  • I 被忽略
  • M 被修改
  • R 被替换
  • X 外部定义创建的版本目录
  • ? 文件没有被添加到本地版本库内
  • !文件丢失或者不完整(不是通过svn命令删除的文件)
  • ~ 受控文件被其他文件阻隔

7、svn delete

删除文件。

svn delete path -m “delete test file”
例如:
1、删除远程服务器文件
svn delete svn://192.168.1.1/pro/domain/test.php  -m “delete test file”
2、删除本地文件,然后提交
svn  delete test.php, 然后再svn ci -m “delete test file”,推荐使用这种
简写:svn (del, remove, rm)

8、svn log

查看日志。

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

如果在工程的根目录使用该命令可能会列出非常多的日志内容,因此为了查找方便,我们通常会使用一些附加参数来配合svn log命令的使用。

查看一段日期的日志

svn log -r {2018-07-03}:{2018-07-09}

显示某一版本范围的log列表

显示从r199687到r199385范围的所有带jaspersong字符串的log (grep下面介绍)

svn log -r r103546:r104414 | grep -A 2 jaspersong

这里说明一下grep -A 2 "jasper"|中A后面数字的差别,不同的数字表示显示的log版本信息不同的行数。

查看某一版本所修改的文件列表及说明

此命名用得比较多。

svn log -r r196674 -v

查找分支所有的修改

svn log -v --stop-on-copy $URL

9、svn info path

查看文件详细信息。

例如:svn info test.php

10、svn diff path

默认将修改的文件与基础版本比较。

例如:svn diff test.php
svn diff -r m:n path(对版本m和版本n比较差异)
例如:svn diff -r 200:201 test.php
简写:svn di

11、svn merge -r m:n path

Linux命令行下将两个版本之间的差异合并到当前文件。

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

12、svn help

Linux命令行下SVN 帮助。

svn help ci

不是常用的命令如下:

13、svn list path

显示path目录下的所有属于版本库的文件和目录。

简写:svn ls

14、svn revert path

下面两种情况都可以用revert命令恢复。

  • (1)不小心写错了很多东西,想撤销所写的东西(还未把修改提交到服务器)
  • (2)不小心删错了文件,想把文件恢复回来(还未把删除提交到服务器)
    注意: 本子命令不会存取网络,并且会解除冲突的状况。但是它不会恢复被删除的目录。【还不没实践过,不知道不会恢复本地删除的目录是什么意思】

15、svn resolved path

移除工作副本的目录或文件的“冲突”状态。

用法: svn resolved path

注意: 【本子命令不会依语法来解决冲突或是移除冲突标记;它只是移除冲突的相关文件,然后让 path 可以再次提交。】

16、svn copy创建分支

  • 从主干上创建分支。

svn cp -m "create branch"  http://svn_server/xxx_repository/trunk  http://svn_server/xxx_repository/branches/br_feature001 
  • 获得分支
svn co http://svn_server/xxx_repository/branches/br_feature001
  • 主干合并到分支
cd br_feature001 

svn merge http://svn_server/xxx_repository/trunk
  • 分支合并到主干
    一旦分支上的开发结束,分支上的代码需要合并到主干。SVN中执行该操作需要在trunk的工作目录下进行。命令如下:
cd trunk 
svn merge --reintegrate http://svn_server/xxx_repository/branches/br_feature001 

17、分支合并到主干一

  • 创建分支
svn copy http://example.com/repos/project/trunk http://example.com/repos/project/branches/beta
  • 合并分支到主干
    在分支上,获取刚开始的版本号
svn log --stop-on-copy  http://example.com/repos/project/branches/search_collect_1108

如得到版本号为:12461

在分支上,获取最新的版本号

svn up

如得到版本号为:12767

切换到主干,然后执行下面命令(后面的路径为,分支的路径。)

svn merge -r 12461:12767  http://example.com/repos/project/branches/search_collect_1108

18、合并一个分支到主干二

  • 查找到分支版本
    方法一:进入分支目录
cd branch 
svn log --stop-on-copy 

最后一个r11340就是创建分支时的reversion

方法二: 进入主干目录

cd trunk
svn -q --stop-on-copy 分支URL  # 这条命令会查询出自创建分支以后分支上的所有修改,最下面的那个版本号就是我们要找的版本号. 
示例:svn log -q --stop-on-copy svn://192.168.1.177/tags/beta_2009_12_24 
  • 合并到主干
    **命令:svn -r 分支版本号:HEAD 分支的URL **
    **解释:HEAD为当前主干上的最新版本 **
示例: 
cd trunk 
svn merge -r 12:HEAD svn://192.168.1.177/tags/beta_2009_12_24 

解决冲突:
使用svn st | grep ^C 查找合并时的冲突文件,手工解决冲突
使用svn resolved filename 告知svn冲突已解决
使用svn commit -m "" 提示合并后的版本

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值