How to use SVN in Eclipse.

In this tutorial we will see how to use SVN in Eclipse and install Subclipse plugin from Eclipse to use SVN, how to add SVN repo, how to commit changes to your SVN repository, how to sync with SVN repo, how to checkout from SVN repo. Please let me know in comments below if I missed any point.

User Guide for Subclipse plugin

Subclipse is an Eclipse plug-in that provides the functionality to interact with a Subversion server, and to manipulate a project on a Subversion server in the Eclipse environment.

Adding Subclipse Plug-in to Eclipse

Go to Help -> Install New Software

Easy method: Select Eclipse Marketplace. Search for Subclipse & click on Install.

Update anyone of the below URLs in Work with input box:

  • https://dl.bintray.com/subclipse/releases/subclipse/latest/
  • https://dl.bintray.com/subclipse/releases/subclipse/4.2.x/

The “latest” site will automatically move on to 4.2.1, 4.3.0, 5.0.0 etc. as those releases are produced. Where as the “4.2.x” site will only pick up new releases in the 4.2.x series such as 4.2.1, 4.2.2 etc. Click on next.

Subclipse Perspectives

To change to the Subclipse perspective select
Window > Open Perspective > Other… > SVN Repository Exploring

OR you can select SVN Repository Exploring directly from Right Pane.

Adding a Repository URL to Subclipse

To add a repository you can right click in the SVN Repository view and select New > SVN Repository, or you can click the add repository button in the toolbar of the SVN Repository view.

Go to SVN Repositories
Click on Add a new SVN Repository
Provide SVN Url (Provide user id and password if asked to)
Click Finish.
Your repository will be located in the SVN Repository view

Checking Out a Project from the Repository

Switch to the SVN Repository Exploring perspective.
Click the + next to your repository. To check out a project right click on any folder/project and select Check Out as Project.

IMP Note: If the project that you are checking out already exists in the workspace, the old project will be destroyed and the project from the SVN repository will be created in its place. Otherwise a new project will be created in the workspace. Switch back to the Java or Plug-in Development perspective to modify the code.

Always change the project name to something else than original SVN project.
Click Finish.

Once checked out you will see project under Java -> Package Explorer

Any changes in the project will be marked by asterisks *

Synchronizing and Committing Resources to the Repository

Any resources that you have modified will have a black asterisk in front of the resource name, and any added will have a question mark in front of the name.

Very IMP Note: It is always a good idea to see what needs to be done before committing files.

To synchronize resources, right click on a project and select Team > Synchronize with Repository…. You will be switched to the Team Synchronizing view.

From there you can look at your outgoing changes, and others incoming changes, and synchronize your code before committing to the repository. Double-clicking on a file will open a side-by-side view of the file and its changes.

If a file has a two-way red arrow on it, then there is a conflict. Someone else has changed that file while you were working on it. Double-click the file to get a compare editor, and copy-paste what you need to resolve onto your local copy. When you have the local copy finished, right-click on the file and choose Mark as Merged. Note: PLEASE USE THIS FEATURE RESPONSIBLY!! Think very hard before selecting “Mark as Merged”, as it will override what is in the repository. An entire history is kept in case you make a mistake, but always pause and check your work before marking as merged.

IMP Note: constantly updating your code from the repository helps avoid conflicts

Synchronizing Resources
To commit changes to files in your project, right click on the project and select Team > Commit…. Or, if you are in the “Team Synchronizing” perspective, right-click on the resources and select “Commit”. Then you will edit the commit comment, or add a new commit comment to document what changes were made. Always add meaningful commit comments! There is also a list of previously used commit comments to choose from. Once you have committed code, the black asterisk should be gone from modified files.

On Commit window: Update the comments with proper artifact number & description

Select all OR modified files and Click Ok

History

To compare your code with the latest from the repository, you may either recheck out the project or right click on the project in the Java/Plug-in Development perspectives and select Compare With > Latest from repository. Using copy and paste, one can recover old code this way. Using Compare With Revision… or Replace With Revision are also helpful.

Also, Team > Show History shows an entire history of a folder/file.

Disconnecting a Project from the Repository

Switch to the Java/Plug-in Development perspective. To disconnect a project from the repository, right click on the project and select Team > Disconnect. Eclipse will prompt asking if you wish to delete the metadata associated with the Subversion connection. Choose No. If you choose yes, you will have to delete the project in your workspace in order to check out another copy of the code.