Version 1.1
Copyright © 2008 - 2011 Lars Vogel
27.06.2011
| Revision History | |||
|---|---|---|---|
| Revision 0.1 | 13.09.2009 | Lars Vogel |
Created |
| Revision 0.2 - 1.1 | 12.11.2009 - 27.06.2011 | Lars Vogel |
bug fixes and enhancements |
Table of Contents
With a distributed version control system you basically do not have a central code repository but everyone has its own branch. To can clone a branch and you always get the full history of the whole branch on your system. You commit into your own branch and you can push your changes to other repositories and other people can pull from you.
The main advantages of distributed version control systems are
Speed: As the whole repository is offline available you can much faster search and compare
Commits: Everyone can commit to his own branch
Another popular distributed version control systems is Git .
Mercurial is a distributed version control system. Mercurial is used by Oracle for the OpenJDK development and offered as a option by Google in Google hosting.
Mercurial is written in Python. Mercurial has a command-line interface. Eclipse provides also a plug-in to use Mercurial.
Install Mercurial on Ubuntu via:
sudo apt-get install mercurial
The installation of Mercurial for other platforms is described in Mercurial installation .
You find binary packages for Mercurial on Window on Binary packages for Windows.
The following will demonstrate a short development cycle using the command line interface of Mercurial.
You will create a new Mercurial repository, create a new Java project and commit the changes to your Mercurial repository.
The command for using Mercurial on the command line is "hg".
Check that you are using Mercurial version 1.3 or higher:
hg --version
Create and switch to your desired work directory .
Initialize a new Mercurial repository with:
hg clone https://yourproject.googlecode.com/hg/ name_of_directory_for_the_clone
hg clone https://yourproject.googlecode.com/hg/ name_of_directory_for_the_clone
Eclipse creates a lot of metadata with regards to the current status of the Eclipse workbench. Also Eclipse creates compiled version in the directory bin. This data should not be placed in the mercurial repository. Create the file ".hgignore" in the same directory as the hg project.
# switch to regexp syntax.
syntax: regexp
^\.metadata
^de.vogella.mercurial.firstproject/bin$
Start Eclipse and use the new directory as workspace. Create a new Java project "de.vogella.mercurial.firstproject". Create the following Java class.
package de.vogella.mercurial.firstproject; public class Test {/** * @param args */public static void main(String[] args) { System.out.println("Hello Mercurial"); } }
Add the project to Mercurial.
hg commit -A -m 'Commit with automatic addremove'
Commit.
hg commit -m "Create new project"
If you have checked out the Mercurial project from another site you can push your changes to the repository.
hg push
Check the history via:
hg log
Rename your Java class to "TestNewName" and create a new class "Test2".
package de.vogella.mercurial.firstproject; public class Test2 {/** * @param args */public static void main(String[] args) { System.out.println("Hello Mercurial"); System.out.println("This is a new class"); } }
Add the new files to Mercurial.
hg commit -A -m 'Commit with automatic addremove'
A rename in Java removes the old file. Mercurial will report these files as missing (hg status). You can use the following command to automatically add the new files and remove the deleted.
Add the new files to Mercurial.
hg addremove
You can now commit. The -A flag in the commit command would also automatically add and remove new files.
hg add .
To see the changes use the status command. diff we show the differences.
hg log hg diff
Before posting questions, please see the vogella FAQ. If you have questions or find an error in this article please use the www.vogella.com Google Group. I have created a short list how to create good questions which might also help you.
http://mercurial.selenic.com/ Mercurial Homepage
http://mercurial.selenic.com/wiki/ Mercurial Wiki
http://hgbook.red-bean.com/ Free Online Mercurial Book from http://hgbook.red-bean.com/
http://bitbucket.org/ Mercurial Hosting service
http://hgbook.red-bean.com/read/ Mercurial: The Definitive Guide
http://code.google.com/p/support/wiki/ConvertingSvnToHg How to convert svn to Mercurial at Google hosting
http://www.javaforge.com/project/HGE EclipseMercurial plug-in homepage
http://javaforge.com/wiki/76402 EclipseMercurial change logs
http://www.javaforge.com/project/HGE/tracker Mercurial Eclipse Bugtracker
vogella Training Android and Eclipse Training from the vogella team
Android Tutorial Introduction to Android Programming
GWT Tutorial Program in Java and compile to JavaScript and HTML
Eclipse RCP Tutorial Create native applications in Java
JUnit Tutorial Test your application
Git Tutorial Put everything you have under distributed version control system