Clone wiki

main / Mercurial_Notes

Mercurial Usage

Mercurial is a bit tricky to get used to, especially when multiple developers are working in parallel.

Multiple Heads

It is recommended that developers commit often. Because each developers has its own repository, this means that multiple heads are created at the "same time". When pulling changes, these multiple heads are pulled into the local repository. For example, in this picture, a developer has committed local changes (L1, and L2) and pulled remote changes (R1, and R2).

Local Changes and Remote Changes

The typical workflow is to:

  1. Pull changes
  2. Merge changes (effortless since most changes do not conflict)
  3. Commit the merge
  4. Proceed with a push or more work...

This is quite tedious. There is thus the possibility to merge the multiple heads into a linear stream when pulling the changes. This process is called rebase. For example, if instead of just pulling the changes, the developer had pulled and rebased the changes, the local history would now look like:

Local and Remote Changes after Rebase

The workflow is now:

  1. Pull changes and select the rebase checkbox in hgeclipse
  2. Done! Proceed with push or more work...

The images were taken from this wonderful wiki page on rebase.


pull rebase

  1. Always commit before pulling and rebasing or updating. Mercurial will force you to do this anyway because it is always better to commit changes and be able to revert if a problem happens while merging/rebasing/updating.
  2. For some reasons, you sometimes need to manually refresh the projects after a rebase.

Corrupted Files (or how to recover from a crash)

If at some point your computer crashes in the middle of a push, it is possible that the local mercurial files become corrupted. Do not worry: all the files on the bitbucket server are safe (push are atomic) and provided that your source file did not get corrupted by a hard disk error, you did not lose anything except the incremental commits. Evidence of commits are error messages like: there is not .hg directory, there is no revlog for file X.

To recover from such situation, follow these steps:

  1. In a temporary folder, clone the current Qualyzer main repository.
  2. Close Eclipse.
  3. In the Eclipse workspace, delete the .hg directory of the main repository (usually located in workspace/main/.hg).
  4. Copy the .hg directory from the cloned repository
  5. Restart Eclipse.
  6. Commit the changes (hg will automatically determine which files are different from the current version of the repository).