详细说明svn分支与合并,以及实例

详细说明svn分支与合并,以及实例

一,svn分支与合并有什么用?

作程序的,对svn在熟悉不过了,但对svn分支熟悉的,我想并不多。因为一般情况下,是用不着svn分支的,其实也没有那个必要。下面我例举几个需要用到svn分支的情况:

1,比较大的项目。比较大的项目,一般情况下会分成几个阶段来完。好比什么五年计划。到了某个阶段时,我建立一个分支,当个备份。万一将来开发下个阶段东西的时候,出现致命错误的时候,我还能把这个分支拿出来接着用。

2,项目要开发新的东西,但是又不想和主干冲突,建立一个分支,单独做为一个开发分支。这样做也是为了责任明确。如果出了问题也好有所查证。

二,创建svn分支

在说创建分支前,关于svn的安装和配置,请参考linux svn安装和配置,不结合apache

1,创建一个代码文件夹main

[root@BlackGhost repos]# pwd
/home/zhangy/checkout/repos
[root@BlackGhost repos]# svn add ./main
A         main
A         main/test.php
[root@BlackGhost repos]# svn commit ./main -m "test"
Adding         main
Adding         main/test.php
Transmitting file data .
Committed revision 5.

2,创建分支

[root@BlackGhost repos]# svn copy svn://127.0.0.1/repos/main svn://127.0.0.1/repos/branch -m "test"

Committed revision 6.

3,查看分支情况

[root@BlackGhost repos]# svn log -v ./branch/test.php
------------------------------------------------------------------------
r6 | zhangy | 2010-10-24 19:59:35 +0800 (Sun, 24 Oct 2010) | 1 line
Changed paths:
A /branch (from /main:5)

test
------------------------------------------------------------------------
r5 | zhangy | 2010-10-24 19:53:20 +0800 (Sun, 24 Oct 2010) | 1 line
Changed paths:
A /main
A /main/test.php

test
------------------------------------------------------------------------

4,注间事项:

a),创建分支,只能在同一个仓库内进行,跨仓库是不行的。会提示svn: No repository found in 'svn://127.0.0.1'

b),创建分支时,注意加上注释,不然会报以下错误。

[root@BlackGhost repos]# svn cp svn://127.0.0.1/repos/main svn://127.0.0.1/repos/branch
svn: Could not use external editor to fetch log message; consider setting the $SVN_EDITOR environment variable or using the --message (-m) or --file (-F) options
svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no 'editor-cmd' run-time configuration option was found

三,合并分支

下面讲一个例子,来说明怎么合并分支。我觉得通过例子,最能让人学到东西了,我在我的博文一在强调这一点。

1,修改main中的文件提交到svn服务器端,这样main的代码就和branch分支的代码就不一样了。

2,把main文件中的文件同步到分支中branch中

  1. [root@BlackGhost branch]# pwd      //是否在分支的文件夹中   
  2. /home/zhangy/checkout/repos/branch   
  3. /**  
  4. 把main的修改同步到branch分支中  
  5. 如果是指定版本的可以svn merge -r 9:10 svn://127.0.0.1/repos/main  
  6. */  
  7. [root@BlackGhost branch]# svn merge svn://127.0.0.1/repos/main               
  8. --- Merging r6 through r8 into '.':     //更新到第8个版本   
  9. U    test.php   
  10. [root@BlackGhost branch]# svn log -v test.php   //查看test.php,从下面我们可以看出,分支版本还是没有变为什么呢?   
  11. ------------------------------------------------------------------------   
  12. r6 | zhangy | 2010-10-24 19:59:35 +0800 (Sun, 24 Oct 2010) | 1 line   
  13. Changed paths:   
  14.  A /branch (from /main:5)   
  15.   
  16. test   
  17. ------------------------------------------------------------------------   
  18. r5 | zhangy | 2010-10-24 19:53:20 +0800 (Sun, 24 Oct 2010) | 1 line   
  19. Changed paths:   
  20.  A /main   
  21.  A /main/test.php   
  22.   
  23. test   
  24. ------------------------------------------------------------------------   
  25. [root@BlackGhost branch]# svn commit -m "test"   //提交   
  26. Sending        .   
  27. Sending        test.php   
  28. Transmitting file data .   
  29. Committed revision 9.   
  30. [root@BlackGhost branch]# svn log -v test.php   //是没因为没有提交,提交后会产生一个新的版本   
  31. ------------------------------------------------------------------------   
  32. r9 | zhangy | 2010-10-24 20:52:22 +0800 (Sun, 24 Oct 2010) | 1 line   
  33. Changed paths:   
  34.  M /branch   
  35.  M /branch/test.php   
  36.   
  37. test   
  38. ------------------------------------------------------------------------   
  39. r6 | zhangy | 2010-10-24 19:59:35 +0800 (Sun, 24 Oct 2010) | 1 line   
  40. Changed paths:   
  41.  A /branch (from /main:5)   
  42.   
  43. test   
  44. ------------------------------------------------------------------------   
  45. r5 | zhangy | 2010-10-24 19:53:20 +0800 (Sun, 24 Oct 2010) | 1 line   
  46. Changed paths:   
  47.  A /main   
  48.  A /main/test.php   
  49.   
  50. test   
  51. ------------------------------------------------------------------------  
[root@BlackGhost branch]# pwd      //是否在分支的文件夹中
/home/zhangy/checkout/repos/branch
/**
把main的修改同步到branch分支中
如果是指定版本的可以svn merge -r 9:10 svn://127.0.0.1/repos/main
*/
[root@BlackGhost branch]# svn merge svn://127.0.0.1/repos/main            
--- Merging r6 through r8 into '.':     //更新到第8个版本
U    test.php
[root@BlackGhost branch]# svn log -v test.php   //查看test.php,从下面我们可以看出,分支版本还是没有变为什么呢?
------------------------------------------------------------------------
r6 | zhangy | 2010-10-24 19:59:35 +0800 (Sun, 24 Oct 2010) | 1 line
Changed paths:
 A /branch (from /main:5)

test
------------------------------------------------------------------------
r5 | zhangy | 2010-10-24 19:53:20 +0800 (Sun, 24 Oct 2010) | 1 line
Changed paths:
 A /main
 A /main/test.php

test
------------------------------------------------------------------------
[root@BlackGhost branch]# svn commit -m "test"   //提交
Sending        .
Sending        test.php
Transmitting file data .
Committed revision 9.
[root@BlackGhost branch]# svn log -v test.php   //是没因为没有提交,提交后会产生一个新的版本
------------------------------------------------------------------------
r9 | zhangy | 2010-10-24 20:52:22 +0800 (Sun, 24 Oct 2010) | 1 line
Changed paths:
 M /branch
 M /branch/test.php

test
------------------------------------------------------------------------
r6 | zhangy | 2010-10-24 19:59:35 +0800 (Sun, 24 Oct 2010) | 1 line
Changed paths:
 A /branch (from /main:5)

test
------------------------------------------------------------------------
r5 | zhangy | 2010-10-24 19:53:20 +0800 (Sun, 24 Oct 2010) | 1 line
Changed paths:
 A /main
 A /main/test.php

test
------------------------------------------------------------------------

到这儿合并基本上就结束了。

3,上面说的是将主干的文件同步到分支中去,把分支的内容同步步主干也是一样的,倒过来就行了。

4,全并的时候,有可能会冲突的,看下面

  1. [root@BlackGhost main]# svn merge svn://127.0.0.1/repos/branch   
  2. Conflict discovered in 'test.php'.    //提示有冲突   
  3. Select: (p) postpone, (df) diff-full, (e) edit,       //在这里让你选择处理方式   
  4. (mc) mine-conflict, (tc) theirs-conflict,   
  5. (s) show all options: p   
  6. --- Merging r7 through r12 into 'test.php':   
  7. C    test.php   
  8. Summary of conflicts:   
  9. Text conflicts: 1       //虽然有冲突,但是还是可以同步了,也说明同步成功了。   
  10.   
  11. --- /tmp/tempfile.2.tmp    Sun Oct 24 21:02:11 2010   
  12. +++ .svn/tmp/test.php.tmp    Sun Oct 24 21:02:11 2010   
  13. @@ -0,0 +1,9 @@   
  14. +<<<<<<< .working   
  15. +asdfadfadfadf   
  16. +111111111111111   
  17. +=======   
  18. +asdfadfadfadf   
  19. +111111111111111   
  20. +222222222222   
  21. +   
  22. +>>>>>>> .merge-right.r12  
[root@BlackGhost main]# svn merge svn://127.0.0.1/repos/branch
Conflict discovered in 'test.php'.    //提示有冲突
Select: (p) postpone, (df) diff-full, (e) edit,       //在这里让你选择处理方式
(mc) mine-conflict, (tc) theirs-conflict,
(s) show all options: p
--- Merging r7 through r12 into 'test.php':
C    test.php
Summary of conflicts:
Text conflicts: 1       //虽然有冲突,但是还是可以同步了,也说明同步成功了。

--- /tmp/tempfile.2.tmp    Sun Oct 24 21:02:11 2010
+++ .svn/tmp/test.php.tmp    Sun Oct 24 21:02:11 2010
@@ -0,0 +1,9 @@
+<<<<<<< .working
+asdfadfadfadf
+111111111111111
+=======
+asdfadfadfadf
+111111111111111
+222222222222
+
+>>>>>>> .merge-right.r12
转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/server/1069.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值