Svn惯例规范管理操作

Svn常规规范管理操作
<div class="iteye-blog-content-contain" style="font-size: 14px;"><div id="article_content" class="article_content">
<p style="margin-top: 0px; margin-bottom: 5px; font-size: 14px; font-family: arial,helvetica,sans-serif;"><span style="font-family: 宋体,'sans serif',tahoma,verdana,helvetica; font-size: 22px;"><strong>一、常规SVN开发过</strong></span><span style="font-family: 宋体,'sans serif',tahoma,verdana,helvetica; font-size: 22px;"><strong>程</strong></span></p>
<p style="margin-top: 0px; margin-bottom: 5px; font-size: 14px; font-family: arial,helvetica,sans-serif;">大多数软件存在这样一个生命周期:编码、测试、发布,然后重复。这样有两个问题,第一,开发者需要在质量保证小组测试假定稳定版本时继续开发新特性,新工 作在软件测试时不可以中断,第二,小组必须一直支持老的发布版本和软件;如果一个bug在最新的代码中发现,它一定也存在已发布的版本中,客户希望立刻得 到错误修正而不必等到新版本发布。</p>
<p style="margin-top: 0px; margin-bottom: 5px; font-size: 14px; font-family: arial,helvetica,sans-serif;">这是版本控制可以做的帮助,典型的过程如下:</p>
<div class="itemizedlist" style="font-size: 14px; font-family: arial,helvetica,sans-serif;">
<ul type="disc">
<li>
<p style="margin-top: 0px; margin-bottom: 5px;"><span class="emphasis"><em>开发者提交所有的新特性到主干。</em></span> 每日的修改提交到<code class="filename" style="font-family: arial,helvetica,sans-serif; font-style: italic;">/trunk</code>:新特性,bug修正和其他。</p>
</li>
<li>
<p style="margin-top: 0px; margin-bottom: 5px;"><span class="emphasis"><em>这个主干被拷贝到“<span class="quote">发布</span>”分支。</em></span> 当小组认为软件已经做好发布的准备(如,版本1.0)然后<code class="filename" style="font-family: arial,helvetica,sans-serif; font-style: italic;">/trunk</code>会被拷贝到<code class="filename" style="font-family: arial,helvetica,sans-serif; font-style: italic;">/branches/1.0</code>。</p>
</li>
<li>
<p style="margin-top: 0px; margin-bottom: 5px;"><span class="emphasis"><em>项目组继续并行工作,</em></span>一个小组开始对分支进行严酷的测试,同时另一个小组在<code class="filename" style="font-family: arial,helvetica,sans-serif; font-style: italic;">/trunk</code>继续新的工作(如,准备2.0),如果一个bug在任何一个位置被发现,错误修正需要来回运送。然而这个过程有时候也会结束,例如分支已经为发布前的最终测试“<span class="quote">停滞</span>”了。</p>
</li>
<li>
<p style="margin-top: 0px; margin-bottom: 5px;"><span class="emphasis"><em>分支已经作了标签并且发布,</em></span>当测试结束,<code class="filename" style="font-family: arial,helvetica,sans-serif; font-style: italic;">/branches/1.0</code>作为引用快照已经拷贝到<code class="filename" style="font-family: arial,helvetica,sans-serif; font-style: italic;">/tags/1.0.0</code>,这个标签被打包发布给客户。</p>
</li>
<li>
<p style="margin-top: 0px; margin-bottom: 5px;"><span class="emphasis"><em>分支多次维护。</em></span>当继续在<code class="filename" style="font-family: arial,helvetica,sans-serif; font-style: italic;">/trunk</code>上为版本2.0工作,bug修正继续从<code class="filename" style="font-family: arial,helvetica,sans-serif; font-style: italic;">/trunk</code>运送到<code class="filename" style="font-family: arial,helvetica,sans-serif; font-style: italic;">/branches/1.0</code>,如果积累了足够的bug修正,管理部门决定发布1.0.1版本:拷贝<code class="filename" style="font-family: arial,helvetica,sans-serif; font-style: italic;">/branches/1.0</code>到<code class="filename" style="font-family: arial,helvetica,sans-serif; font-style: italic;">/tags/1.0.1</code>,标签被打包发布。</p>
<p style="margin-top: 0px; margin-bottom: 5px;">具体操作可参考</p>
</li>
</ul>
</div>
<p style="margin-top: 0px; margin-bottom: 5px; font-size: 14px; font-family: arial,helvetica,sans-serif;">整个过程随着软件的成熟不断重复:当2.0完成,一个新的2.0分支被创建,测试、打标签和最终发布,经过许多年,版本库结束了许多版本发布,进入了“<span class="quote">维护</span>”模式,许多标签代表了最终的发布版本。</p>
<p style="margin-top: 0px; margin-bottom: 5px; font-size: 14px; font-family: arial,helvetica,sans-serif;"> </p>
<p style="margin-top: 0px; margin-bottom: 5px; font-size: 14px; font-family: arial,helvetica,sans-serif;"><span style="font-family: 宋体,'sans serif',tahoma,verdana,helvetica; font-size: 22px;"><strong>二、具体操作:</strong></span></p>
<p style="margin-top: 0px; margin-bottom: 5px; font-size: 14px; font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif; font-size: 14px;">上面阐述了常规的开发管理,现在我们来看下具体的操作,下面文章引用地址:<a href="http://www.cnblogs.com/cxd4321/archive/2012/07/12/2588110.html" target="_blank">http://www.cnblogs.com/cxd4321/archive/2012/07/12/2588110.html</a></span></p>
<p style="margin-top: 0px; margin-bottom: 5px; font-size: 14px; font-family: arial,helvetica,sans-serif;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">首先需要安装TortoiseSVN,我安装的版本是:TortoiseSVN 1.6.15, Build 21041 - 32 Bit , 2011/03/23 18:00:27</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><span style="line-height: 24px; font-size: 16px;"><strong>1、本地Repository的创建</strong></span></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">repository的创建很简单,假设我要在D:\TortoiseSVN\TestRepository目录中创建repository,只需右键 TestRepository目录,依次选择"TortoiseSVN" -&gt; "Create repository here"便完成了repository的创建。</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><span style="line-height: 24px; font-size: 16px;"><strong>2、Check out</strong></span></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">假设要check out到D:\TortoiseSVN\TestSVN,同样很简单,在D:\TortoiseSVN目录下创建TestSVN目录,然后在该目录上右 键,选择"SVN Check out...",在弹出的窗口中的"URL of repository"中填入"file:///D:/TortoiseSVN/TestRepository",其他默认即可,最后点击ok。</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><span style="line-height: 24px; font-size: 16px;"><strong>3、trunk创建新项目MyProject</strong></span></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">相当简单就不赘述了,只列出本次操作所作出的修改:</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><img style="border: 0px none;" src="http://hi.csdn.net/attachment/201107/14/0_1310654241E8hh.gif" alt=""></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><span style="line-height: 24px; font-size: 16px;"><strong>4、创建branch</strong></span></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">在/trunk/MyProject目录上右键,依次选择"TortoiseSVN" -&gt; "Branch/tag...",在弹出窗口的"To URL"中填入分支的地址,在这里目标revision选择HEAD revision,如下图所示,添加log后点击ok分支便建立了。这个操作速度非常快,新建的branch在repository中其实只是一个指向 trunk某个revision的软连接而已,并没有真的复制文件。</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><img style="border: 0px none;" src="http://hi.csdn.net/attachment/201107/14/0_1310654533q26t.gif" alt=""></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><span style="line-height: 24px; font-size: 16px;"><strong>5、Check out分支</strong></span></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">右键TestSVN目录选择"TortoiseSVN Update"即可将刚刚建立的分支下载回本地。进入/branches/MyProject目录下你会发现其文件结构和/trunk/MyProject一模一样。</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><span style="line-height: 24px; font-size: 16px;"><strong>6、branch提交一个新文件</strong></span></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><img style="border: 0px none;" src="http://hi.csdn.net/attachment/201107/14/0_1310655182jGGW.gif" alt=""></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><span style="line-height: 24px; font-size: 16px;"><strong>7、trunk紧接着提交一个修改</strong></span></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><img style="border: 0px none;" src="http://hi.csdn.net/attachment/201107/14/0_131065523464l9.gif" alt=""></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><span style="line-height: 24px; font-size: 16px;"><strong>8、branch再次提交一个修改</strong></span></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><img style="border: 0px none;" src="http://hi.csdn.net/attachment/201107/14/0_1310655316Fc0M.gif" alt=""></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><span style="line-height: 24px; font-size: 16px;"><strong>9、将trunk中的修改同步到branch</strong></span></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">6-8演示的是branch和trunk在独立、并行地开发。为了防止在“错误”的道路上越走越远,现在branch意识到是时候和trunk来一次同步了(将trunk合并到branch)。</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">首先,在本地trunk中先update一下,有冲突的解决冲突,保证trunk和repository已经完全同步,然后在/branches /MyProject上右键,依次选择"TortoiseSVN" -&gt; “Merge...”,在弹出的窗口中选择第一项"Merge a range of revision",这个类型的Merge已经介绍得很清楚,适用于将某个分支或主线上提交的多个revision间的变化合并到另外一个分支上。</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><img style="border: 0px none;" src="http://hi.csdn.net/attachment/201107/14/0_13106558532uPR.gif" alt=""></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">点击next后,出现如下窗口:</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><img style="border: 0px none;" src="http://hi.csdn.net/attachment/201107/14/0_13106562442ZQZ.gif" alt=""></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">由于是要从trunk合并到branch,理所当然这里的"URL to merge from"应该填trunk的路径,"Revision range to merge"很好理解,就是你要将trunk的哪些revision所对应的变化合并到branch中,可以是某一连串的revision,比如 4-7,15-HEAD,也可以是某个单独的revision号。由于在r4中,trunk修改了Person.java中的talk()方法,所以这里 的revision只需填4即可。点击next后出现下图:</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><img style="border: 0px none;" src="http://hi.csdn.net/attachment/201107/14/0_1310656626mx9H.gif" alt=""></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">在这里只需保留默认设置即可。在点击Merge按钮前你可以先Test merge一把,看成功与否,以及merge的详细信息。点击Merge按钮后trunk所做的修改将同步到branch中。</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><span style="line-height: 24px; font-size: 16px;"><strong>10、提交合并后的branch</strong></span></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><img style="border: 0px none;" src="http://hi.csdn.net/attachment/201107/14/0_13106569839g4f.gif" alt=""></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">至此,branch已经完全和trunk同步,branch和trunk的代码相处很融洽,没有任何冲突,如果branch已经开发结束,那是时候将branch合并回trunk了,当然,如果branch还要继续开发,那你将不断地重复6-10这几个步骤。</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><span style="line-height: 24px; font-size: 16px;"><strong>11、将branch合并回trunk</strong></span></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">在/trunk/MyProject上右键(注意是在主线的目录上右键),依次选择"TortoiseSVN" -&gt; "Merge...",在弹出的窗口中,Merge type选择第二项"Reintegrate a branch",这种类型的合并适合在分支开发结束后将所有的改动合并回主线。</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><img style="border: 0px none;" src="http://hi.csdn.net/attachment/201107/14/0_13106573597hYb.gif" alt=""></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">点击next后出现如下窗口:</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><img style="border: 0px none;" src="http://hi.csdn.net/attachment/201107/14/0_131065774486Zw.gif" alt=""></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">在这里,"From URL"选择/branches/MyProject,无需选择revision号,Reintegrate会将branch上所有修改合并到 trunk。后面的步骤和上文第9步中的一样,不再啰嗦了。如无意外,branch将成功合并到trunk,你需要做的只是将合并后的trunk赶紧 commit!</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><span style="line-height: 24px; font-size: 16px;"><strong>12、提交合并后的trunk</strong></span></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">so easy...</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><span style="line-height: 24px; font-size: 16px;"><strong>13、删除branch</strong></span></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">如果你认为你新加的功能已经开发完成了,你可以删除你的分支</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">到这里,我已经给你演示完了整个过程,我一身的汗也下来了,不过最后我们还是看看所有的log信息吧,通过log能发现我们干的所有事情:</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><img style="border: 0px none;" src="http://hi.csdn.net/attachment/201107/14/0_1310658093DCD2.gif" alt=""></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">r1-r7正是我上文在干的事情,从Message中你能发现我对trunk和branch都干了什么,另外,在Log Messages窗口的左下角勾选了"Include merged revisions"你还能看到额外的Merge information:</p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"><img style="border: 0px none;" src="http://hi.csdn.net/attachment/201107/14/0_1310658311B1x5.gif" alt=""></p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;"> </p>
<p style="line-height: 26px; font-family: Arial; color: #333333; font-size: 14px;">图中灰色的是和merge相关的log,共发生了两次merge,第一次是在r6,在r6中,branch合并了trunk在r4时提交的变化;第二次是在r7,在r7中,trunk合并了branch从r2到r6的所有变化。</p>
<br><p style="margin-top: 0px; margin-bottom: 5px; font-size: 14px; font-family: arial,helvetica,sans-serif;"><span style="font-family: 宋体,'sans serif',tahoma,verdana,helvetica; font-size: 22px;"><strong>三、结束语</strong></span></p>
<p style="margin-top: 0px; margin-bottom: 5px;"><span style="font-family: arial,helvetica,sans-serif; font-size: 14px;">通过整篇的文章,大家应该已经知道trunk/branches/tags的用途及基本操作使用,如果还需要了解svn更多的使用特性,请参阅<a href="http://www.subversion.org.cn/svnbook/1.4/index.html" target="_blank">http://www.subversion.org.cn/svnbook/1.4/index.html</a></span></p>
</div></div>