linux命令——svn分支创建、合并

简介: 详细说明svn分支与合并,以及实例  一,svn分支与合并有什么用?作程序的,对svn在熟悉不过了,但对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中

 

[plain]  view plain copy
  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. ------------------------------------------------------------------------  


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

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

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

[plain]  view plain copy
  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  


来自连接:http://blog.csdn.net/heihuifeng/article/details/7525932
目录
相关文章
|
3天前
|
安全 网络协议 Linux
linux必学的60个命令
Linux是一个功能强大的操作系统,提供了许多常用的命令行工具,用于管理文件、目录、进程、网络和系统配置等。以下是Linux必学的60个命令的概览,但请注意,这里可能无法列出所有命令的完整语法和选项,仅作为参考
197 2
|
1天前
|
存储 Linux Shell
YUM管理器的命令列表-Linux
YUM管理器的命令列表-Linux
8 0
|
3天前
|
Linux 程序员 计算机视觉
【linux 学习】在Linux中经常用到的cmake、make、make install等命令解析
【linux 学习】在Linux中经常用到的cmake、make、make install等命令解析
16 0
|
3天前
|
Linux
Linux的find命令使用
【5月更文挑战第11天】Linux的find命令使用
15 3
|
3天前
|
监控 Linux 数据处理
|
3天前
|
编解码 Ubuntu Linux
|
3天前
|
JSON Linux 数据格式
Linux命令发送http
请注意,`curl`命令非常灵活,可以根据您的需求进行多种配置和自定义。您可以查看 `curl`命令的文档以获取更多详细信息。
13 0
|
3天前
|
安全 Linux 测试技术
|
3天前
|
安全 Linux Windows
Linux中Shutdown命令使用介绍
Linux中Shutdown命令使用介绍
13 2
|
3天前
|
缓存 关系型数据库 Linux
Linux目录结构:深入理解与命令创建指南
Linux目录结构:深入理解与命令创建指南