SVN使用—高级用法

一、SVN分支

Branch 选项会给开发者创建出另外一条线路。当有人希望开发进程分开成两条不同的线路时,这个选项会非常有用。

情景:
比如项目 demo 下有两个小组,svn 下有一个 trunk 版。
由于客户需求突然变化,导致项目需要做较大改动,此时项目组决定由小组 1 继续完成原来正进行到一半的工作(某个模块),小组 2 进行新需求的开发。

那么此时,我们就可以为小组2建立一个分支,分支其实就是 trunk 版(主干线)的一个copy版,不过分支也是具有版本控制功能的,而且是和主干线相互独立的,当然,到最后我们可以通过(合并)功能,将分支合并到 trunk 上来,从而最后合并为一个项目。

[root@localhost test]# ls
hello.html  test01  test02  test03
[root@localhost test]# svn copy test02/ test04
A         test04
[root@localhost test]# ls
hello.html  test01  test02  test03  test04
[root@localhost test]# svn status
A  +    test04
[root@localhost test]# svn commit -m "add test04"
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
Adding         test04

Committed revision 6.
[root@localhost test]# ll test04/
total 4
-rw-r--r-- 1 root root 38 Feb 26 13:33 old.html
[root@localhost test04]# vim index.html
[root@localhost test04]# svn status
?       index.html
[root@localhost test04]# svn add index.html
A         index.html
[root@localhost test04]# svn commit -m "add index.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
Adding         test04/index.html
Transmitting file data .
Committed revision 7.

切换到test02,执行svn update,然后将test04分支合并到test02中。

root@runoob:~/svn/runoob01/trunk# svn merge ../branches/my_branch/
--- Merging r10 into '.':
A    index.html
--- Recording mergeinfo for merge of r10 into '.':
 G   .

root@runoob:~/svn/runoob01/trunk# ll
total 16
drwxr-xr-x 2 root root 4096 Nov  7 03:52 ./
drwxr-xr-x 6 root root 4096 Jul 21 19:19 ../
-rw-r--r-- 1 root root   36 Nov  7 02:23 HelloWorld.html
-rw-r--r-- 1 root root    0 Nov  7 03:52 index.html
-rw-r--r-- 1 root root   22 Nov  7 03:06 readme

root@runoob:~/svn/runoob01/trunk# svn commit -m "add index.html"
Adding         index.html
Transmitting file data .
Committed revision 11.

二、SVN 标签(tag)

版本管理系统支持 tag 选项,通过使用 tag 的概念,我们可以给某一个具体版本的代码一个更加有意义的名字。
Tags 即标签主要用于项目开发中的里程碑,比如开发到一定阶段可以单独一个版本作为发布等,它往往代表一个可以固定的完整的版本,这跟 VSS 中的 Tag 大致相同。

[root@localhost test]# svn copy test04/ v1.0
A         v1.0
[root@localhost test]# ls v1.0/
index.html  old.html
[root@localhost test]# svn status
A  +    v1.0
[root@localhost test]# svn commit -m "tags v1.0"
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
Adding         v1.0
Adding         v1.0/index.html

Committed revision 8.

三、其他命令及用法

(1)resolve命令
解决版本冲突的命令。在冲突解决之后,需要使用svn resolved来告诉subversion冲突解决,这样才能提交更新。

(2)import命令(导入)

svn import Armatrue svn://192.168.0.249/svn/ninjiaSourceCode/trunk/Armatrue --username=xiaohuang --password=123456 -m "import new project"

(3)export命令(导出)

svn export -r 2232 svn://10.11.22.11/svn/project001

(4)文件锁
一般用于二进制内容,因为无法合并。
如果某个文件加锁,其他用户的本地工作拷贝(更新后)将是只读的。
当该用户提交后,其他用户的本地工作拷贝(更新后)才可以写操作。
其他用户可以“撬锁”,然后进行写操作。
高级配置可以配置“撬锁”权限,使不是什么人都可以“撬锁”。

四、SVN中的可用命令

   add
   blame (praise, annotate, ann)
   cat
   changelist (cl)
   checkout (co)
   cleanup
   commit (ci)
   copy (cp)
   delete (del, remove, rm)
   diff (di)
   export
   help (?, h)
   import
   info
   list (ls)
   lock
   log
   merge
   mergeinfo
   mkdir
   move (mv, rename, ren)
   propdel (pdel, pd)
   propedit (pedit, pe)
   propget (pget, pg)
   proplist (plist, pl)
   propset (pset, ps)
   resolve
   resolved
   revert
   status (stat, st)
   switch (sw)
   unlock
   update (up)
原文地址:https://www.cnblogs.com/tongxiaoda/p/8472831.html