﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-魔头工坊-随笔分类-编程工具</title><link>http://www.blogjava.net/superliuwr/category/39402.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 08 May 2009 08:18:03 GMT</lastBuildDate><pubDate>Fri, 08 May 2009 08:18:03 GMT</pubDate><ttl>60</ttl><item><title>Subversion 分支操作</title><link>http://www.blogjava.net/superliuwr/archive/2009/05/06/269214.html</link><dc:creator>Marvin</dc:creator><author>Marvin</author><pubDate>Wed, 06 May 2009 04:06:00 GMT</pubDate><guid>http://www.blogjava.net/superliuwr/archive/2009/05/06/269214.html</guid><wfw:comment>http://www.blogjava.net/superliuwr/comments/269214.html</wfw:comment><comments>http://www.blogjava.net/superliuwr/archive/2009/05/06/269214.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/superliuwr/comments/commentRss/269214.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/superliuwr/services/trackbacks/269214.html</trackback:ping><description><![CDATA[<p><font size="2"><font color="#000080"><em>V2 Updated by Marvin @ May 6, 2009</em></font> </font> </p>
<p><font size="2">整理自免费的svnbook 中文版</font> </p>
<p>&nbsp; </p>
<p><strong><font color="#000080" size="4">创建分支</font></strong>  </p>
<p>创建分支最快捷简便的方法就是直接对url操作，然后从新的url co出工作拷贝。在Subversion server上，用硬链接的方式处理不同version之间相同的文件。  </p>
<p><strong>svn copy <a href="http://svn.example.com/svnroot/comet/trunk">http://svn.example.com/svnroot/comet/trunk</a>&nbsp;<a href="http://svn.example.com/svnroot/comet/branches/2.8">http://svn.example.com/svnroot/comet/branches/2.8</a> &#8211;m &#8220;creating a private branch of comet&#8221;</strong>  </p>
<p><strong><font color="#000080" size="4"></font></strong>&nbsp; </p>
<p><strong><font color="#000080" size="4">合并一个分支上的修改到主干</font></strong>  </p>
<p>Subversion的分支合并不是一个高风险的事情。其实Subversion并没有真正意义的分支概念，只有copy，但每个copy都会保留其所有的历史信息。像Clearcase那样的单独一个维度的version tag是不存在的，Subversion中的tag只是用来做快照而已，而且本质上也是copy，如果你提交新东西，那它就和branch是一样的。  </p>
<p>简单地说，它一共只做了两件事。第一，比较两个版本的不同，这和你用svn diff得到的结果是一样的，只是svn diff会把changes打印出来。第二，把changes应用到你指定的工作拷贝上去，这表现为你的工作拷贝的本地修改，你可以在这个基础上再做修改，或是检查有没有问题，然后再提交。Subversion server并不关心你的提交是来自svn merge的修改，还是你自己改的代码。如果对结果不满意或者后悔了，一样可以用svn revert取消本地修改。  </p>
<p>一个好的习惯是，提交的时候在注释中写清楚是从那个版本merge过来的。  </p>
<p>Best practice 关于从某分支上merge changes到主干：  </p>
<p><strong>step1：找到前一次合并到主干时的version(341)</strong>  </p>
<blockquote>
<p>svn log &#8211;v &#8211;-stop-on-copy <a href="http://svn.example.com/svnroot/comet/branches/2.8">http://svn.example.com/svnroot/comet/branches/2.8</a></p>
</blockquote>
<p><strong>step2：切换到trunk的本地工作目录</strong>  </p>
<p><strong>step3：update到最新，获得当前HEAD的version(405)</strong>  </p>
<blockquote>
<p>svn update</p>
<p>我们只用比较分支的初始状态和最终状态，然后把这些changes merge到主干上去，而不是分支的初始状态和主干的最终状态。</p>
</blockquote>
<p><strong>step4：merge</strong>  </p>
<blockquote>
<p>svn merge &#8211;r 341:405 <a href="http://svn.example.com/svnroot/comet/branches/2.8">http://svn.example.com/svnroot/comet/branches/2.8</a></p>
<p>此处省略了目标工作拷贝，默认是当前目录的工作拷贝，也可以指定</p>
<p>svn merge &#8211;r 341:405 <a href="http://svn.example.com/svnroot/comet/branches/2.8">http://svn.example.com/svnroot/comet/branches/2.8</a> my_trunk_copy</p>
</blockquote>
<p><strong>step5：查看merge后的状态</strong>  </p>
<blockquote>
<p>svn status</p>
</blockquote>
<p><strong>step6：编译测试看有无问题</strong>  </p>
<p><strong>step7：提交</strong>  </p>
<blockquote>
<p>svn commit &#8211;m &#8220;Merged 2.8 changes r341:405 into the trunk.&#8221;</p>
</blockquote>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong><font color="#0000a0" size="4"></font></strong>&nbsp;</p>
<p><strong><font color="#0000a0" size="4">切换到另一个分支</font></strong></p>
<p>如果你不是同时在几个分支上工作，那么没有必要在你的机器上保留多个不同分支的工作拷贝。你可以用svn switch在不同的分支间切换。</p>
<p>例如你现在的工作拷贝是基于2.8 branch的，你想切换到trunk上去，只要运行</p>
<p>svn switch <a href="http://svn.example.com/svnroot/comet/trunk">http://svn.example.com/svnroot/comet/trunk</a></p>
<p>svn switch 还可以接受-r 参数来制定要切换的版本号，也支持只对部分目录执行版本切换。</p>
<img src ="http://www.blogjava.net/superliuwr/aggbug/269214.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/superliuwr/" target="_blank">Marvin</a> 2009-05-06 12:06 <a href="http://www.blogjava.net/superliuwr/archive/2009/05/06/269214.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>