做了几个月的实际项目,感觉还是只用到CVS的皮毛,CVS中的高级功能比如create tag、create branch和merge等都未使用过。Dreamhead发过来一本”pragmatic version control-using CVS”,顺便do some practice and research on the advanced functions of CVS。

1、Tags、Branches and Tagging的概念理解
Tags分为Regular tag和Branch tag两种。
Regular tag其实就是我们一般理解中的tag,而Branch tag即是我们理解中的branch。
HEAD也是一个特殊的分支,the main branch,只是我们把它默认当作main trunk。

建立分支的必要性,举个简单的例子当我们的项目对外release1.0版本后,比如我们对整个project建立version为“Release_1_0”,但是这个版本肯定有bug存在,我们就这样提交给用户使用,相信不会等多久bug report就会feedback回来。所以我们得一边做下一个版本Release_2_0的开发一边fix bug,而我们fix bug时基于的版本只能使release1.0,这时我们就要考虑难道新版本的开发和fix bug的工作都要在main trunk 上么,这样可行么?回答是“也许可行,但是不用过多久你就会发现这样会造成太多的冲突,开发人员的抱怨声也越来越多”。Branch可以帮助我们解决这个难题。我们在建立version Release_1_0的同时建立一个branch,比如叫做“Release_1_0_Branch”,并同时建立一个regular tag ”Root_of_Releas_1_0_Branch”,这个regular tag的用途是为了以后branch 合并到main trunk时提供一个参考点。之后开发新版本的人员就基于main trunk工作,而fix bug的人员就基于Release_1_0_Branch工作。一旦在Release_1_0_Branch上将Release_1_0的bug修复了,我们就可以将Release_1_0_Branch合并到main trunk中来一次性remove the bugs。上面举的这个例子只是branch较简单的一个用法。有效的利用branch会给你的项目的开发带来很多便捷的。

下面的英文段落是从某书中摘录的关于version和branch的说明。
You can use CVS to maintain different branches of a project. Doing so is often
necessary if you release a version of your project to the public, such as version 1.0.
As you begin to work on adding new features for version 2.0, the code is not stable
enough for release; so, if any serious bugs are discovered in version 1.0, they must
be made to the original 1.0 code. CVS allows you to create a separate branch,
starting with the original 1.0 code, so you can maintain this code separately from
the new development continuing with the main branch, HEAD.
//…
Versions differ from branches. A version is a snapshot of a branch at a given
point in time—in other words, it’s a particular set of file revisions.
//….
Adding a version label to a project associates the revision number of each particular
file with a single project-level label.You should consider tagging a project with a version label at all significant development milestones, such as a beta or an official release, or before any drastic
change is undertaken.

2、Merge
理解了branch的概念后,那我们如何将一个Branch合并(Merge)到main trunk or another branch呢?下面我们使用Eclipse作为工具来说明如何将branch合并到其他branch中(main trunk is also a branch , a special branch)。

在你在CVS中创建branch后一段时间,你可能要将你在branch中的changes合并到其他branch中。要想将你的branch中的changes合并到其他branch中,你首先要知道“the name of your branch”and “the version from which your branch was created”。

知道上面的两样后,我们就可以实施我们的merge了。我们以branch merge到HEAD为例。具体步骤如下:

* 目标version加载
首先将目标version 加载到你的工作区,在这个例子里我们将HEAD version加载进来,具体方法是在你工作区(可能是“Navigator view”)中,Right click your project name, choose Replace With > Another Branch or Version from the context menu. Then select the HEAD to replace with your current version in your workplace。

* 选择branch
Select the project and choose Team > Merge.
在随后出现的对话框中,你首先选择“the version from which the branch was created.”,然后在下一步中选择你的Branch。

* Synchronize view中的操作
在第二步结束后,Synchronize view中将显示“all the differences between the branch and your workspace version(that is the HEAD version)”,你必须在Synchronize view中通过菜单中提供的“Update, Override and Update, or Mark as Merged”手工决定合并到你工作区的change。

* Commit the changes
在所有期望的changes都被merge到你的工作区后,你就可以“commit”the changes to the repository了。

注:Merge actions:
Update – Running this action will bring the changes into the file in the workspace. Any conflicts that are not auto-mergable will be skipped.

Override and Update – This action is enabled on files with conflicting changes. Running this action will discard any local changes you have and replace the file with the remote contents.

Mark as Merged – This action will remove the selected changes from the view. The changes will only reappear if the remote state of the resource changes and the CVS Merge Synchronization is refreshed.

© 2004, bigwhite. 版权所有.

Related posts:

  1. CVS Primer
  2. C++ Advanced Training(二)
  3. C++ Advanced Training(一)
  4. 本不是第一篇的第一篇
  5. Java 5.0新特性研究(一)