Working with Branches


Two useful functions when working with CVS files are the ability to tag and branch the repository. Tagging a repository provides a snapshot of the repository that you can use to later check out or diff against. For example, you could tag the repository before committing a large and potentially dangerous change. If you need to roll back the change, you can just use the tag with the update command to get back to the state before the commit.

Branching a repository makes a separate line of development that you can work on without merging it into the main trunk of the repository. For example, you may need to create a bug-fix branch for the current release while also continuing work on the next release in the trunk.

Creating a Tag

To create a tag in the repository:

  1. Right-click the project or folder you want to tag and choose CVS | Tag.

  2. Specify a name for the branch.

  3. If you want to check that you have committed all local modifications before you create the tag, select the Avoid Tagging Locally Modified Files checkbox.

  4. If the tag already exists, but is set on an earlier revision of the files you are tagging, select the Move Existing Tag checkbox. The IDE removes the tag from the earlier revision and assigns it to the revision you are tagging.

  5. Click Tag.

Once you have tagged the repository, you can update or check out a repository from the point where the tag was made by entering the tag name in the Check Out command dialog box.

Creating a Branch

A branch is created using "sticky tags." When you switch to a branch, your local files are tagged with the branch's sticky tags. Any commands that you run on the files, like update and commit, only work with the branch. For example, if you update the files, you only get changes that were made on the branch, not in the trunk.

To create a new branch in the repository:

  1. Right-click the project, folder, or file you want to branch and choose CVS | Create Branch.

  2. Enter the branch name. Make sure the branch name does not already exist in the repository. You can use the Browse button to review the existing branch names.

    Do not use the Branch command to switch to an existing branch. Instead, use the Switch to Branch command.


  3. Specify whether to tag the files before creating the branch and the name of the tag. Tagging the files before branching makes it easy to get a snapshot of the files before the branch was made.

  4. Specify whether you want your files to be switched to the branch or whether you just want to create the branch but continue working in the trunk or current branch.

Viewing a Working Directory's Branch

By default, the IDE only displays which branch a working directory is on in the title bar of the Versioning window. You can turn on the display of branch information in the IDE, so that each file displays its branch name in the IDE windows and Source Editor tabs. To display branch information, choose View | Show CVS Status Labels.

If no branch name is displayed, the working directory files are from the repository trunk.

Switching Between Branches

You should always commit your local changes to your working directory before switching to a branch, or your local changes could be lost.

To switch to a branch:

  1. Right-click the project or folder that you want to switch to a branch and choose CVS | Switch to Branch.

  2. Choose whether to switch to the trunk or to a branch. You can click Browse to see all of the available branches. Do not enter a tag name in the Switch to Branch dialog box.

  3. Click Switch. The IDE updates the repository to the branch. Any files that exist on the branch to which you are switching are created. Any files that do not exist in the branch you are switching to are deleted.

Merging from a Branch

Merging from a branch can be tricky. You can often get multiple merge conflicts in files that have been modified in both the trunk and the branch. Here are some hints that can help:

  • Always commit all of your changes before doing the merge. Do not have any locally modified files in your working directory.

  • Always tag your branch after a merge, and then use that tag as the starting point for your next merge. For example, if you create a branch and one week later do a merge to synch the branch with the trunk, you usually have to resolve a few merge conflicts. If you then merge from the same point a week later, you have to resolve the same merge conflicts all over again. You should therefore only merge changes that were made after the point of your last merge.

  • If you just need to integrate one fix and do not want to merge an entire branch back, you can use the Search History command to find the commit that included the fix. You can then export that commit as a patch and apply the patch to the trunk.

To merge the trunk from a branch:

  1. If you do not have the trunk checked out, check out the trunk and open the working directory in the IDE, either by opening the working directory in the Favorites window or opening the projects.

  2. Right-click the project or folder that you want to merge from a branch and choose CVS | Merge from Branch.

  3. Select Merge from Branch and enter the name of the branch you are merging from.

  4. If necessary, choose to only merge changes from a specific tag.

  5. If necessary, choose to tag the trunk or branch after the merge is complete. Doing so gives you an easy starting point for the next merge.



NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net