• SVN使用—常用命令及避免冲突的方法


    一、SVN启动

    [root@localhost ~]# mkdir /data/svn
    [root@localhost ~]# svnadmin create /data/svn/test
    [root@localhost ~]# svnserve -d -r /data/svn/test --listen-port 3700
    [root@localhost ~]# netstat -tnlp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
    tcp        0      0 192.168.1.69:59878          0.0.0.0:*                   LISTEN      1676/sshd           
    tcp        0      0 0.0.0.0:3700                0.0.0.0:*                   LISTEN      29913/svnserve
    

    -r: 配置方式决定了版本库访问方式。
    --listen-port: 指定SVN监听端口,不加此参数,SVN默认监听3690

    由于-r 配置方式的不一样,SVN启动就可以有两种不同的访问方式
    方式一:-r直接指定到版本库(称之为单库svnserve方式)

    svnserve -d -r /data/svn/test
    

    在这种情况下,一个svnserve只能为一个版本库工作。
    authz配置文件中对版本库权限的配置应这样写:

    [groups]
    admin=user1
    dev=user2
    
    [/]
    @admin=rw
    user2=r
    * =   其他用户没有权限
    

    使用类似这样的URL:svn://192.168.0.1/ 即可访问test版本库。

    方式二:指定到版本库的上级目录(称之为多库svnserve方式)

    svnserve -d -r /data/svn
    

    这种情况,一个svnserve可以为多个版本库工作
    authz配置文件中对版本库权限的配置应这样写:

    [groups]
    admin=user1
    dev=user2
    [test:/]
    @admin=rw
    user2=r
    
    [test01:/]
    @admin=rw
    user2=r
    

    如果此时你还用[/],则表示所有库的根目录,同理,[/src]表示所有库的根目录下的src目录。
    使用类似这样的URL:svn://192.168.0.1/test即可访问test版本库。

    二、创建版本库

    [root@localhost ~]# svnadmin create /data/svn/test
    [root@localhost ~]# ll /data/svn/test
    total 24
    drwxr-xr-x 2 root root 4096 Feb 26 11:10 conf
    drwxr-sr-x 6 root root 4096 Feb 26 11:10 db
    -r--r--r-- 1 root root    2 Feb 26 11:10 format
    drwxr-xr-x 2 root root 4096 Feb 26 11:10 hooks
    drwxr-xr-x 2 root root 4096 Feb 26 11:10 locks
    -rw-r--r-- 1 root root  229 Feb 26 11:10 README.txt
    

    svn目录说明:

    • dav目录:是提供apache与mod_dav_svn使用的目录,让他们存储内部数据
    • db目录:就是所有版本控制的数据存放文件
    • hooks目录:放置hook脚本文件的目录
    • locks目录:用来放置subversion建库锁定数据的目录,用来追踪存取文件库的客户端
    • format文件:是一个文本文件,里面只放了一个整数。表示当前文件库配置的版本号
    • conf目录:是这个仓库的配置文件(仓库的用户访问账号、权限等)

    进入/opt/svn/runoob01/conf目录 修改默认配置文件配置,包括svnserve.conf、passwd、authz 配置相关用户和权限。

    1、svn服务配置文件svnserve.conf
    svn服务配置文件为版本库目录中的文件conf/svnserve.conf。

    [root@localhost test]# cd conf/
    [root@localhost conf]# ls
    authz  passwd  svnserve.conf
    
    [general]
    # anon-access = read  定义非授权用户的访问权限,有三种方式: none 、read 、write ,设置为none限制访问,read为只读, write为具有读写权限,默认为read。
    # auth-access = write  定义授权用户的访问权限,有三种方式: none 、read 、write ,设置为none限制访问, read为只读, write为具有读写权限,默认为write 。
    # password-db = passwd  定义保存用户名和密码的文件名称,这里为passwd,和该文件位于同一目录。
    # authz-db = authz  定义保存授权信息的文件名称,这里为authz,和该文件位于同一目录。
    # realm = My First Repository  定义客户端连接时的“认证命名空间”, Subversion会在认证提示里显示,并且作为凭证缓存的关键字。
    
    [sasl]  用于标识是否进行SASL加密处理
    # use-sasl = true  是否开启sasl
    # min-encryption = 0
    # max-encryption = 256
    变量min-encryption和max-encryption控制服务器所需要的加密强度。
    

    2、用户名口令文件passwd
    用户名口令文件由svnserve.conf的配置项password-db指定,缺省为conf目录中的passwd。该文件仅由一个[users]配置段组成。
    [users]配置段的配置行格式如下:

    [users]
    # harry = harryssecret
    # sally = sallyssecret
    

    3、权限配置文件
    权限配置文件由svnserve.conf的配置项authz-db指定,缺省为conf目录中的authz。该配置文件由一个[groups]配置段和若干个版本库路径权限段组成。
    [groups]配置段中配置行格式如下:

    [groups]
    g_admin = admin,thinker
    
    [admintools:/]
    @g_admin = rw
    * =
    
    [test:/home/thinker]
    thinker = rw
    * = r
    

    三、SVN检出操作

    [root@localhost ~]# svn checkout svn://192.168.1.69:3700/test --username=user01
    Authentication realm: <svn://192.168.1.69:3700> test
    Password for 'user01': 
    
    -----------------------------------------------------------------------
    ATTENTION!  Your password for authentication realm:
    
       <svn://192.168.1.69:3700> test
    
    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)? no
    Checked out revision 0.
    [root@localhost ~]# ls   检出成功后在当前目录生成test文件夹
    anaconda-ks.cfg  install.log  install.log.syslog  test
    [root@localhost ~]# ll test/
    total 0
    

    查看版本库信息

    [root@localhost ~]# svn info svn://192.168.1.69:3700/test --username=user01
    Authentication realm: <svn://192.168.1.69:3700> test
    Password for 'user01': 
    
    -----------------------------------------------------------------------
    ATTENTION!  Your password for authentication realm:
    
       <svn://192.168.1.69:3700> test
    
    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)? no
    Path: test
    URL: svn://192.168.1.69:3700/test
    Repository Root: svn://192.168.1.69:3700/test
    Repository UUID: d120c548-f91f-4039-8278-1648c0339d64
    Revision: 0
    Node Kind: directory
    Last Changed Rev: 0
    Last Changed Date: 2018-02-26 11:10:56 +0800 (Mon, 26 Feb 2018)
    

    四、SVN提交操作

    [root@localhost ~]# cd test/
    [root@localhost test]# ls
    [root@localhost test]# vim hello.html
    [root@localhost test]# svn status
    ?       hello.html
    

    此时hello.html的状态为?,说明它还未加到版本控制中。
    将文件readme加到版本控制,等待提交到版本库。

    [root@localhost test]# svn add hello.html 
    A         hello.html
    [root@localhost test]# svn status
    A       hello.html
    

    此时hello.html的状态为A,它意味着这个文件已经被成功地添加到了版本控制中。
    为了把hello.html存储到版本库中,使用commit -m加上注释信息来提交。
    如果你忽略了 -m 选项, SVN会打开一个可以输入多行的文本编辑器来让你输入提交信息。

    [root@localhost test]# svn commit -m "Hello"
    Authentication realm: <svn://192.168.1.69:3700> test
    Password for 'user01': 
    
    -----------------------------------------------------------------------
    ATTENTION!  Your password for authentication realm:
    
       <svn://192.168.1.69:3700> test
    
    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)? no
    Adding         hello.html
    Transmitting file data .
    Committed revision 1.
    

    现在hello.html被成功地添加到了版本库中,并且修订版本号自动增加了1。

    五、SVN解决冲突

    版本冲突原因:
    假设 A、B 两个用户都在版本号为 100 的时候,更新了 kingtuns.txt 这个文件,A 用户在修改完成之后提交 kingtuns.txt 到服务器, 这个时候提交成功,这个时候 kingtuns.txt 文件的版本号已经变成 101 了。同时B用户在版本号为 100 的 kingtuns.txt 文件上作修改, 修改完成之后提交到服务器时,由于不是在当前最新的 101 版本上作的修改,所以导致提交失败。

    使用admin用户修改hello.html
    [root@localhost test]# cat hello.html 
    HelloWorld! http://www.test.com/tong
    [root@localhost test]# cat hello.html 
    HelloWorld! http://www.test.com/tong
    [root@localhost test]# svn diff
    Index: hello.html
    ===================================================================
    --- hello.html	(revision 1)
    +++ hello.html	(working copy)
    @@ -1 +1 @@
    -HelloWorld! http://www.test.com/
    +HelloWorld! http://www.test.com/tong
    提交修改
    [root@localhost test]# svn commit -m "Tong"
    Authentication realm: <svn://192.168.1.69:3700> test
    Password for 'admin': 
    
    -----------------------------------------------------------------------
    ATTENTION!  Your password for authentication realm:
    
       <svn://192.168.1.69:3700> test
    
    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)? no
    Sending        hello.html
    Transmitting file data .
    Committed revision 2.
    使用user01继续修改hello.html
    [root@localhost test]# svn diff
    Index: hello.html
    ===================================================================
    --- hello.html	(revision 1)
    +++ hello.html	(working copy)
    @@ -1 +1 @@
    -HelloWorld! http://www.test.com/
    +HelloWorld! http://www.test.com/test
    [root@localhost test]# cat hello.html 
    HelloWorld! http://www.test.com/test
    尝试提交
    [root@localhost test]# svn commit -m "Hello02"
    Authentication realm: <svn://192.168.1.69:3700> test
    Password for 'admin': 
    
    -----------------------------------------------------------------------
    ATTENTION!  Your password for authentication realm:
    
       <svn://192.168.1.69:3700> test
    
    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)? no
    Sending        hello.html
    Transmitting file data .svn: Commit failed (details follow):
    svn: File '/hello.html' is out of date
    

    这时我们发现提交失败了。
    因为此时,Hello.html 已经被admin修改并提交到了仓库。Subversion不会允许user01提交更改,因为admin已经修改了仓库,所以我们的工作副本已经失效。

    为了避免两人的代码被互相覆盖,Subversion不允许我们进行这样的操作。所以我们在提交更改之前必须先更新工作副本。所以使用update命令,如下:

    [root@localhost test]# svn update
    Authentication realm: <svn://192.168.1.69:3700> test
    Password for 'admin': 
    
    -----------------------------------------------------------------------
    ATTENTION!  Your password for authentication realm:
    
       <svn://192.168.1.69:3700> test
    
    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)? no
    Conflict discovered in 'hello.html'.
    Select: (p) postpone, (df) diff-full, (e) edit,
            (mc) mine-conflict, (tc) theirs-conflict,
            (s) show all options: mc
    G    hello.html
    Updated to revision 2.
    

    这里输入"mc",以本地的文件为主。你也可以使用其选项对冲突的文件进行不同的操作。
    默认是更新到最新的版本,我们也可以指定更新到哪个版本。

    svn update -r6
    

    此时工作副本是和仓库已经同步,可以安全地提交更改了

    [root@localhost test]# svn commit -m "change Hello02"
    Authentication realm: <svn://192.168.1.69:3700> test
    Password for 'admin': 
    
    -----------------------------------------------------------------------
    ATTENTION!  Your password for authentication realm:
    
       <svn://192.168.1.69:3700> test
    
    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)? no
    Sending        hello.html
    Transmitting file data .
    Committed revision 3.
    

    六、SVN版本回退

    [root@localhost test]# cat hello.html 
    HelloWorld! http://www.test.com/test?
    [root@localhost test]# svn status
    M       hello.html
    [root@localhost test]# svn revert hello.html 
    Reverted 'hello.html'
    [root@localhost test]# svn status
    [root@localhost test]# cat hello.html 
    HelloWorld! http://www.test.com/test
    

    revert 操作不单单可以使单个文件恢复原状, 而且可以使整个目录恢复原状。恢复目录用 -R 命令,如下:

    svn revert -R test
    

    但是,假如我们想恢复一个已经提交的版本怎么办。
    为了消除一个旧版本,我们必须撤销旧版本里的所有更改然后提交一个新版本。这种操作叫做 reverse merge。
    首先,找到仓库的当前版本,现在是版本22,我们要撤销回之前的版本,比如版本21:

    svn merge -r 22:21 hello.html
    

    七、SVN查看历史信息

    通过svn命令可以根据时间或修订号去除过去的版本,或者某一版本所做的具体的修改。以下四个命令可以用来查看svn 的历史:

    • svn log: 用来展示svn 的版本作者、日期、路径等等。
    • svn diff: 用来显示特定修改的行级详细信息。
    • svn cat: 取得在特定版本的某文件显示在当前屏幕。
    • svn list: 显示一个目录或某一版本存在的文件。

    (1)svn log
    可以显示所有的信息,如果只希望查看特定的某两个版本之间的信息,可以使用:

    查看当前版本号
    [root@localhost test]# svn info
    Path: .
    URL: svn://192.168.1.69:3700/test
    Repository Root: svn://192.168.1.69:3700/test
    Repository UUID: d120c548-f91f-4039-8278-1648c0339d64
    Revision: 2
    Node Kind: directory
    Schedule: normal
    Last Changed Author: admin
    Last Changed Rev: 2
    Last Changed Date: 2018-02-26 12:08:37 +0800 (Mon, 26 Feb 2018)
    
    [root@localhost test]# svn log -r 1:2
    Authentication realm: <svn://192.168.1.69:3700> test
    Password for 'admin': 
    
    -----------------------------------------------------------------------
    ATTENTION!  Your password for authentication realm:
    
       <svn://192.168.1.69:3700> test
    
    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)? no
    ------------------------------------------------------------------------
    r1 | user01 | 2018-02-26 12:01:34 +0800 (Mon, 26 Feb 2018) | 1 line
    
    Hello
    ------------------------------------------------------------------------
    r2 | admin | 2018-02-26 12:08:37 +0800 (Mon, 26 Feb 2018) | 1 line
    
    Tong
    ------------------------------------------------------------------------
    

    如果只想查看某一个文件的版本修改信息,可以使用 svn log 文件路径。

    [root@localhost test]# svn log hello.html 
    Authentication realm: <svn://192.168.1.69:3700> test
    Password for 'admin': 
    
    -----------------------------------------------------------------------
    ATTENTION!  Your password for authentication realm:
    
       <svn://192.168.1.69:3700> test
    
    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)? no
    ------------------------------------------------------------------------
    r3 | admin | 2018-02-26 12:13:32 +0800 (Mon, 26 Feb 2018) | 1 line
    
    change Hello02
    ------------------------------------------------------------------------
    r2 | admin | 2018-02-26 12:08:37 +0800 (Mon, 26 Feb 2018) | 1 line
    
    Tong
    ------------------------------------------------------------------------
    r1 | user01 | 2018-02-26 12:01:34 +0800 (Mon, 26 Feb 2018) | 1 line
    
    Hello
    ------------------------------------------------------------------------
    

    如果希望得到目录的信息要加 -v。
    如果希望显示限定N条记录的目录信息,使用 svn log -l N -v。

    [root@localhost test]# svn log -l 2 -v
    Authentication realm: <svn://192.168.1.69:3700> test
    Password for 'admin': 
    
    -----------------------------------------------------------------------
    ATTENTION!  Your password for authentication realm:
    
       <svn://192.168.1.69:3700> test
    
    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)? no
    ------------------------------------------------------------------------
    r2 | admin | 2018-02-26 12:08:37 +0800 (Mon, 26 Feb 2018) | 1 line
    Changed paths:
       M /hello.html
    
    Tong
    ------------------------------------------------------------------------
    r1 | user01 | 2018-02-26 12:01:34 +0800 (Mon, 26 Feb 2018) | 1 line
    Changed paths:
       A /hello.html
    
    Hello
    ------------------------------------------------------------------------
    

    (2)svn diff
    用来检查历史修改的详情。

    • 检查本地修改
    • 比较工作拷贝与版本库
    • 比较版本库与版本库

    如果用 svn diff,不带任何参数,它将会比较你的工作文件与缓存在 .svn 的"原始"拷贝。

    [root@localhost test]# svn diff
    Index: hello.html
    ===================================================================
    --- hello.html	(revision 3)
    +++ hello.html	(working copy)
    @@ -1 +1 @@
    -HelloWorld! http://www.test.com/test
    +HelloWorld! http://www.test.com/test?123456
    

    比较工作拷贝和版本库

    [root@localhost test]# svn diff -r 2 hello.html 
    Authentication realm: <svn://192.168.1.69:3700> test
    Password for 'admin': 
    
    -----------------------------------------------------------------------
    ATTENTION!  Your password for authentication realm:
    
       <svn://192.168.1.69:3700> test
    
    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)? no
    
    -----------------------------------------------------------------------
    ATTENTION!  Your password for authentication realm:
    
       <svn://192.168.1.69:3700> test
    
    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)? no
    Index: hello.html
    ===================================================================
    --- hello.html	(revision 2)
    +++ hello.html	(working copy)
    @@ -1 +1 @@
    -HelloWorld! http://www.test.com/tong
    +HelloWorld! http://www.test.com/test?123456
    

    比较版本库与版本库

    [root@localhost test]# svn diff -r 1:2 hello.html 
    Authentication realm: <svn://192.168.1.69:3700> test
    Password for 'admin': 
    
    -----------------------------------------------------------------------
    ATTENTION!  Your password for authentication realm:
    
       <svn://192.168.1.69:3700> test
    
    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)? no
    Index: hello.html
    ===================================================================
    --- hello.html	(revision 1)
    +++ hello.html	(revision 2)
    @@ -1 +1 @@
    -HelloWorld! http://www.test.com/
    +HelloWorld! http://www.test.com/tong
    

    (3)svn cat
    如果只是希望检查一个过去版本,不希望查看他们的区别,可使用svn cat

    [root@localhost test]# svn cat -r 2 hello.html 
    Authentication realm: <svn://192.168.1.69:3700> test
    Password for 'admin': 
    
    -----------------------------------------------------------------------
    ATTENTION!  Your password for authentication realm:
    
       <svn://192.168.1.69:3700> test
    
    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)? no
    HelloWorld! http://www.test.com/tong
    

    (4)svn list
    可以在不下载文件到本地目录的情况下来察看目录中的文件:

    [root@localhost test]# svn list svn://192.168.1.69:3700/test
    Authentication realm: <svn://192.168.1.69:3700> test
    Password for 'admin': 
    
    -----------------------------------------------------------------------
    ATTENTION!  Your password for authentication realm:
    
       <svn://192.168.1.69:3700> test
    
    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)? no
    hello.html
    
  • 相关阅读:
    关于oracle数据库(10)函数
    关于oracle数据库(9)
    关于oracle数据库(8)查询2
    关于oracle数据库(7)查询1
    关于oracle数据库(6)约束
    关于oracle数据库(5)增删改查
    关于oracle数据库(4)数据类型
    爬虫之beautifulsoup
    影视项目报错情况及处理
    多app应用等系列汇总
  • 原文地址:https://www.cnblogs.com/tongxiaoda/p/8472182.html
Copyright © 2020-2023  润新知