站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Netbeans 专题Using CVS in NetBeans IDE 5.0

Using CVS in NetBeans IDE 5.0

摘要: This tutorial is intended as an introduction to using the built-in CVS module in NetBeans IDE 5.0. This tutorial assumes no familiarity with the CVS modules from previous IDE releases and will not address differences between the CVS support in NetBeans IDE 5.0 and CVS support in previous versions. This tutorial assumes that you have access to a CVS repository that you can check out.

Introduction

In this tutorial, you will create a new project based on your CVS repository and explore how to use the CVS tools available in NetBeans IDE 5.0.

Prerequisites

This tutorial assumes you have a basic familiarity with the NetBeans IDE 5.0 and that you have access to a CVS repository. We will use the NetBeans sources repository as an example.

Software Needed for the Tutorial

Before you begin, you need to install the following software on your computer:

Notations Used in the Tutorial

<NETBEANS_HOME> - the NetBeans IDE installation directory
<PROJECT_HOME> - directory that contains the project you create.

Tutorial Exercises

Checking out your repository

The goal of this exercise is to check out your repository and create a project from it.

Configuration and Check-Out

  1. In the IDE, choose CVS > Checkout from the menu to open the Checkout window.

  2. In the CVS Root field, enter the value of the CVS_ROOT for your repository. If you are unfamiliar with the cvs root syntax, you can alternatively click the Edit button and enter the required fields using the dialog. If you need to use :ext: or :extssh:, use :ext:; then in the main Checkout window, an SSH configuration form will appear. For the NetBeans sources for instance, the finnished CVS_ROOT looks like this:

    :pserver:johndoe@cvs.netbeans.org:/cvs

  3. In the password field, enter the password for logging into the repository.

  4. If you're behind a firewall, click Proxy Configuration to configure your proxy server. Click Next. If the authentication fails, you will be asked to correct the settings.

  5. When the authentication succeeds, you will be taken to the second screen. In the Module field, enter the name of the module you want to check out. Alternatively, you can click Browse to choose from a list of available modules.

  6. If you're checking out a specific branch, enter the branch tag name under Branch, otherwise leave the Branch field empty.

  7. In the Local Path field, enter the path to the directory where you want the check-out to reside on your local host. Click Finish.

Creating a Project

The IDE will now check out your files into the local working directory you specified. When it's finished, it will ask if you'd like to create a new project from the checked-out sources. Click Yes. If the checked-out sources are not a NetBeans project yet, the New Project wizard opens.

  1. In the New Project wizard, when creating a new project in the same directory as the check-out, you must choose a project type that allows for existing source files, such as Java Project With Existing Sources. Click Next.

  2. In the Name and Location dialog box, enter the desired project properties and click Next.

  3. In the Existing Sources dialog box, click Add Folder to include the path to the check-out in the project's source paths list.

  4. Click Finish to create and open the project.

If you have a repository that has already been checked out locally, you can simply created a new project from these sources by choosing File > New Project from the menu; you can also add the check-out directory to the source path list for an existing project. NetBeans IDE will automatically recognize that the directory holds version-controlled files and will allow you to perform CVS operations on it.

Summary

In this exercise, you checked out a repository and created a project from it.

Exercise 2: Understanding the notations

One of the most compelling features of the NetBeans IDE 5.0 CVS support is the information automatically provided about files under CVS control. This status information is accessible in the Favorites, Files and Projects windows, as well as the Versioning window. In this exercise, you'll explore the meaning of the various symbols and colors the IDE uses to indicate CVS file states.

Most Common Symbols and Colors

  1. Select the Projects tab and expand a source directory node for the project. Expand one of the package nodes. Notice that nothing looks unusual. When files in a CVS repository are unmodified (Status: Up-to-date), the file names look normal.

  2. Now open one of the source files. Change a word and save the file. Notice that the file name is now blue. When a local file has been modified, the file name is blue.

  3. Also notice the small, blue badge on the package and source directory nodes. When a file in a directory is locally modified or new, the directory and all parent directories are annotated with that badge. In the case of packages, this badge applies only to the package itself and not its subpackages.

  4. Right-click a package node and select New > Java Class. In the dialog box, click Finish to create a new class called NewClass.java. Notice that the file name for the new class is green. Files which have been created but are not yet commited have green file names. Also, as with modified files, the containing directories are annotated with a blue badge.
    Note that with NetBeans IDE 5.0, when you add or create a file in a repository, that file automatically has a cvs add applied. New files are however not actually added to the repository until changes are committed.

  5. Righ-click NewClass.java and select CVS > Ignore. Notice that the file name for the new class is now gray. A gray label indicates the file is ignored by CVS and will not be part of any versioning commands (update, commit, etc).

  6. Right-click on a file in the package node and select Refactor > Rename. In the dialog box, rename the file in the New Name field, and deselect Preview All Changes. Click Next. Notice that the renamed file's file name is now also green.
    The IDE automatically performed a cvs remove on the old file and a cvs add on the new file. Again, the changes won't be applied to the repository until they are committed.

  7. Right-click a different file in the package node and select Delete. Notice that the file simply goes away. The IDE automatically performs a cvs remove on the deleted file. Again, the change won't be applied until changes are commited.

  8. Select View > Show CVS Status Labels. Notice that new and modified files are now labeled as such with a text label, in addition to the coloring.

Summary

In this exercise, you learned how the IDE indicates the status of files in a CVS repository.

Exercise 3: Updating your files

When changes are made to the CVS repository, the changes get propagated to your local check-out through a CVS update operation. In this exercise, you will learn how to perform an update on your local check-out and how to interpret the output from the update operation.

Update

  • Select CVS > Update All Files. This operation will update all of the files from all the open projects. This is useful if you have more than one repository associated with a single project, or if you're working on more than one project at once.

  • From the Projects or Files tab, right-click any of the nodes and select CVS > Update. This will update that node and recusively update any files contained in that node.

  • From the Projects or Files tab, right-click any file and select CVS > Update. This action will update that file. You can use the Shift and/or Control keys to select multiple files.

  • Select Window > Versioning. From the toolbar in the Versioning frame, click the third button — The tool tip will identify it as Update All. This has the same effect as CVS > Update All Files.

Remember to always update a file to its latest revision before you start editing, and also right before you commit changes!

Resolving Conflicts

Sometimes when you update, a change you have made in your local check-out will conflict with a change made in the remote repository. When this happens, a dialog box appears notifying you that there is a conflict and the color of the file name will change to red.
If you look at the file in the Editor window, you will also see conflict markers (<<<<< and >>>>>) highlighting conflicting sections. Any directories containing a conflicting file will have a small, red icon attached to them.

  1. To resolve the conflicts, right-click the conflicted file and select CVS > Resolve Conflicts. This option will present you with a graphical Merge Conflicts Resolver in the Editor window, and will allow you to resolve them.

  2. Conflicts are marked by red lines. You resolve a conflict by accepting one of the two revisions. For each conflict, click Accept above the pane containing the text that you wish to accept. Once you have chosen the correct text, it is highlighted in green and displayed in the Merge Result pane. The text you did not choose is highlighted in blue. You can also edit the source file manually.

  3. Use the Next and Previous Difference buttons in the upper-lefthand corner to navigate to each conflict in the file.

  4. The IDE merges the accepted revision with the source file. You can see the results of the merge in the bottom pane of the Merge Conflicts Resolver.

  5. Important: When you are done and all conflicts are resolved, select File > Save to save these changes! Alternatively, press Ctrl-S to save. The file is saved if its Editor tab is not marked with an asterisk.

  6. Once all conflicts are resolved and saved, click OK to exit the Merge Conflicts Resolver. The red Merge Conflict badge is removed from the file and you can now commit the modified file.

In the event that you have deleted a file that has been modified, you can resolve the conflict by right-clicking on the directory which contains the deleted file and selecting CVS > Show Changes. The Versioning window displays the list of modified files. Find the entry for the deleted file in the modified file list, right-click it and select Revert Delete.

Interpreting the output

Select the Output tab. (It may be sharing the same space as the Versioning window.) In the Output window, you will find a tab for each of your repositories on which you've performed an operation. If the operation was an update, you will find a list of the files which changed. The output is the same as from the CVS command-line utility.

Summary

In this exercise, you learned how to update your check-out and resolve conflicts.

Exercise 4: Showing changes

It is often useful to see what changes have been made to your local check-out. In this exercise, you will learn how to show changes to your check-out.

Status Overview

  1. Select CVS > Show All Changes. This will open the Versioning window and will display a list of files which have changed, either locally or remotely.

  2. From the toolbar of the Versioning window, select the All tab. This tab shows all changes to all repositories.

  3. From the toolbar of the Versioning window, select the Local tab. This tab shows all changes to all repositories that have happened in your local check-out.

  4. From the toolbar of the Versioning window, select the Remote tab. This tab shows all changes to all repositories that have happened in the remote repository.

  5. From the Projects, Favorites or Files window, right-click a node and select CVS > Show Changes. This will open the Versioning window and show all changes to the repository which have happened within that node. If you right-click on a file and select CVS > Show Changes, only changes to that file will be displayed. You can use the Shift and/or Control keys to select multiple files.

  6. From the Projects, Favorites or Files window, right-click a node and select CVS > Search History. Wait for the Search History Window to display all log messages for this file. You can now browse all log messages for each commited change.

Diffing changes

  1. Select CVS > Diff All Files. This will open a diff view in the Editor window which shows diffs of all changed files. The diff view is a split window showing both files you want to compare. Use the "up arrow" and "down arrow" buttons in the toolbar to step through the changes.

  2. From the Projects or Files tab, right-click a node that has modifications and select CVS > Diff. This will open a diff view in the Editor window which shows diffs of all changed files within that node.

  3. If you right-click a file and select CVS > Diff, a diff view of only that file will be shown. You can use the Shift and/or Control keys to select multiple files.

Note that you cannot perform a diff on files which have not been modified.

Showing annotations

  1. Open a file from your repository.

  2. In the Projects or Files tab, right-click the file and select CVS > Show Annotations. The left margin next to each line in the Editor window will now show which version of the file was the last to contain a change to that line, and who committed the change.

  3. In the Projects or Files tab, right-click the file and select CVS > Hide Annotations. The headers are now gone again.

Summary

In this exercise, you learned how to show changes to your check-out.

Exercise 5: Committing changes

In order for the changes you've made to your local check-out to be applied to the remote repository, you have to commit your changes. In this exercise, you'll learn how to commit changes you've made.

Commit

  1. Select CVS > Commit All Files. This will open a commit dialog which shows you the changes which will be committed and gives you the option of entering text describing the changes: Make sure to enter a log message that is descriptive (state whether you added, removed or replaced lines, and why). If you click Commit, the commit command is performed and the changes you made are committed to the repository. Note: Click Cancel because you do not actually want to commit the changes you've made during this tutorial.

  2. From the Projects or Files tab, right-click a node and select CVS > Commit. This will open a commit dialog which shows the changes which will be committed and gives you the option of entering text describing the commit. Only changes to files within the selected node will be committed. Using the Shift and/or Control keys, you can select multiple files to commit. If you click Commit the commit command is performed and the changes you made are committed to the repository. Note: Click Cancel because you do not actually want to commit the changes you've made during this tutorial.

  3. Select CVS > Show All Changes. In the Versioning window, right-click a modified file and select Exclude from Commit. That file's changes will now not be committed when you perform a commit. The file is marked with a strikethrough label.

  4. Right-click the same file again and select CVS > Include in Commit. The file's label looks normal again. That file's changes will now be committed when you perform a commit operation.

Summary

In this exercise, you learned how to commit changes.

Exercise 6: Reverting changes

Sometimes you want to undo the changes you've made instead of committing them. In this exercise, you'll learn how to revert changes you've made.

Revert

  1. From the Projects or Files tab, right-click a modified (not added or deleted) file and select CVS > Revert Modifications. A dialog box will ask if you're certain you want to overwrite the file. Click Yes. Your changes have now been discarded, and the file contains the latest repository version.

  2. You can perform the same command from the Versioning window. Right-click a modified file in the Versioning window and select Revert Modifications. A dialog box will ask if you're certain you want to overwrite the file. Click the Yes button. Your changes have now been discarded, and the file contains the latest repository version.

  3. In the Versioning window, right-click a deleted file and select Revert Delete. A dialog box will ask if you're certain you want to overwrite the file. Click Yes. The deleted file has now been restored, and the file contains the latest repository version.

  4. To "revert" a newly added file, simply delete the file locally.

Make sure that you revert all changes made in the course of this tutorial.

Summary

In this exercise, you learned how to revert changes.

Conclusion

This CVS tutorial showed you how to work with version controlled files in NetBeans IDE. You learned how to check out your repository, how to interpret the file status, how to update your files, how to view and commit changes, and how to revert changes.

Next Steps


↑返回目录
前一篇: Understanding the Travel Reservation Service
后一篇: Using Hibernate with NetBeans4.1 and SJSAS 8.1