Using Mercurial: Local Repository
Creating a repository
If an Eclipse project already exists: (assume it is present in a directory called myprogram
)
cd ~/eclipse_work/myprogram
hg init
The hg init
command sets up a local Mercurial repository.
Alternatively, if you are using an online repository, to start your project
you would begin by cloning the repository. Then you can create a new Eclipse
project by importing the directory you set up.
Updating the local repository
Once the local repository is in place, there are two different types of updates to perform. First, files in the directory are not automatically
present in the repository. Hence, whenever a new file is added, use the
hg add
command to add it to the repository. No filename argument
is required; every file in the directory not already present in the repository
will be added.
Once you are ready to commit changes to the local repository, use
hg commit
. In a multi-person project, use hg commit -u userid
; that way, the person who committed changes can be identified
readily. Each commit will require a comment describing the changes that
have been made.
You can view the history of commits using hg log
.
Switching back to an old version
If you are unhappy with the current version in your local repository and
you would like to revert to an earlier version, you can use hg revert
. If, for example, your current revision is version 15, and you would like
to revert to version 10, you would type:
hg revert --all --rev 10
This will create "version 16" which is identical to version 10. The --all
forces all files to revert; if you only want to revert some of them, list the appropriate filenames.