Mercurial¶
Introduction to Mercurial (hg)¶
Here is an introductory talk on version control (html slides, pdf, rst).
The bundle of the repository, or the tgz and zip version of the repository are available.
(My) Mercurial FAQ¶
Where is the keyword substitution (in cvs/svn terms)?¶
See http://www.selenic.com/mercurial/wiki/index.cgi/KeywordExtension. This extension is bundled in version 1.0 (if not earlier).
Observations:
In the context of keyword expansion: the $Date: 2012/01/09 09:35:40 $ tag (and the Date information in the $Id: hg.txt,v 96ab4df1c4c6 2012/01/09 09:35:40 fangohr $ keyword) contains the date in the UTC time (i.e. Greenwich mean time), whereas entries in the log are shown in the local time of the committer.
Can I pull from several different repositories?¶
Yes, see http://www.selenic.com/mercurial/wiki/index.cgi/CommunicatingChanges for details.
How do I know what revision my working directory is?¶
In subversion language, the question is “what is the equivalent hg
command for svn info?”
The answer is the id command, and the parent command.
An extended explanation: Assume you have a repository with (at least) three revisions. You now go back to an older version. In this (simple) education example, let’s assume we use:
$> hg update -r 0
to go back to version 0. The question is: how can I check for this
directory at a later point which version it is? The id command provides this answer (in principle):
$> hg id
c2696a428dc5
Usually, it is more convenient (and valid for the local repository) to use the numeric id:
$> hg id -n
0
Note that there exists the related parent command, which shows the
parent(s) of the working directory, and the date of the parent
revision and some more information:
$> hg parents
changeset: 0:c2696a428dc5
user: Hans Fangohr [phi] <fangohr@soton.ac.uk>
date: Wed Mar 12 09:50:33 2008 +0000
summary: initial commit
Use Mercurial without access to server (using bundles)¶
Problem¶
Suppose we have developer A and B that need to work on the same project, but cannot access any mercurial servers jointly (typically due to firewalls, restrictions imposed by employer, etc). Suppose A hold the repository THEREPO from which the work is meant to start.
Solution¶
Somehow, A needs to give B a copy of the repository (mail, email, usbstick, ftp server, …). Suppose the current tip of that repository is 4f45839f613c:
if A makes a change to the repository, he needs to create a bundle:
$> cd THEREPO $THEREPO> hg bundle --base 4f45839f613c changes.bundle
and email the bundle changes.bundle to B. This bundle contains all changes since the specified base version.
B can simply pull from that file (and update afterwards):
$> cd THEREPO_at_B $THEREPO_at_B> hg pull changes.bundle
If the bundle contains changes that are already present in B‘s
version of THEREPO, then these will be ignored when pulling. As
long as the bundle doesn’t grow to large, this allows to use the
bundle command with the same --base revision again and again to
create bundles including further changes. A bit wasteful, but convenient.
If B wants to communicate changes to A, he needs to follow the same instructions (to create a bundle and email it to A).
The scenario described above can be dealt with more elegantly: it just outlines the basic idea.
Other things to know about bundles:
these are (very well) compressed. It is hard to create a better compression of hg repositories than using bundles.
hg bundle --base null backup.bundlecreates a (compressed) backup of the repository.
Mercurial on Windows¶
Recommend to use Tortoise Hg.
Download and install, reboot as instructed.
How to clone an ssh repository¶
There are two options:
Using the command line¶
Use the usual hg commands, for example
$> hg clone ssh://somemachine.some.domain//somedirectorypath
or
$> hg clone ssh://username@somemachine.some.domain//somedirectorypath
if your username at somemachine.some.domain is different from your local name.
Using the graphical interface¶
Right click on some selected document or folder. Choose TortoiseHg->Clone a Repository
In the resulting menu, add the address as above, i.e.
$> hg clone ssh://somemachine.some.domain//somedirectorypath
or
$> hg clone ssh://username@somemachine.some.domain//somedirectorypath
You also need to specify the target location on your local machine’s directory structure.
Click Clone (top left corner), and you will have to enter the password of username@somemachine.some.domain. If correct, the repository will be cloned to the local machine.
(This was testing with TortoiseHG 0.6)
Removing a changeset from a repository¶
This is discussed in many places. See for example http://stackoverflow.com/questions/907133/mercurial-remove-changeset-from-remote-branch
Merging¶
Keep my changes or their changes¶
How to go back to earlier version and continue from there?¶
A nice summary from Martin Geisler is available at http://stackoverflow.com/questions/2540454/mercurial-revert-back-to-old-version-and-continue-from-there .