zoukankan      html  css  js  c++  java
  • 详细说明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 plaincopy  [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,全并的时候,有可能会冲突的,看下面 
    
    [plain] view plaincopy  [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   
  • 相关阅读:
    c++中stl函数的使用
    java 中String类的常见方法和StringBuffer类的使用
    c++模板类和模板函数
    c++简单工厂类的设计模式
    Android自定义的button按钮
    c++基类与派生类之间的转换
    Unity和Android结合出现Unabled to convert class into dex format
    jz2240用tftp下载程序步骤
    解决jz2440不能ping同主机问题
    android中的事件传递机制
  • 原文地址:https://www.cnblogs.com/zendu/p/4981233.html
Copyright © 2011-2022 走看看