Mercurial

Common Commands

hg init
Creates a new repository
hg clone source destFolder
Copies a repo
hg verify
Makes sure it isn’t FUBAR
hg add
Start tracking untracked files
hg commit
Lock in a set of changes
hg push
Send a changeset to another repo
hg update
Integrate someone else’s changeset

Pushing from Local to Dev

When doing Mercurial work at the U:

  1. Map to the Dev server (smb://)
  2. Check for new change sets
  3. Prior to doing a push, do a hg verify (run on the Dev machine or else it will be REALLY slow).
  4. Make sure Dev and Prod are in sync.
  5. Do your push to Dev.
  6. If it goes completely FUBAR, copy the .hg folder over from Prod.

Ways to Undo Changes

Revert

Backs out all modifications to the last commit.

Rollback

This will undo the last transaction such as a commit, pull, etc.

Backout

Undo effect of a commit by adding to the repository the inverse of the last commit.

Histedit

This is a Mercurial extension that allows you to do surgery on a repo.

Many Modified Files, but They Are Identical

When updating the entire .hg folder from the Windows servers onto my local machine, SourceTree or Mercurial will show that there are thousands of modified files, but diff shows that they are identical. This is because some tracked flag is different.

The fix is easy, just Revert all the local changes. In SourceTree, this is done by highlighting your current branch and then clicking the big “Revert” button on the toolbar.

You may then have to apply standard Drupal security permissions.

Branching

There are several ways to branch in Mercurial, but common consensus seems to recommend "Named Branches". I believe this is the method that happens when clicking the "Branch" button inside SourceTree. Creating a branch will label the Working Copy, but it is not actually created until you do the first commit. (Hence people creating commits called "stupid commit", etc.)

Closing Branches

Once you are done with a branch, you probably should close it. There are a few methods:

--close-branch

hg commit --close-branch

I'm not exactly sure, but I think this just means do not list in active branches command (hg branches)

Clone

The recommended procedure to really eliminate unwanted heads is to use hg clone --rev. First, you rename your current repo to a backup. Then you clone the backup back to the original name, but you specify --rev X where X is the parent of the first of the chain of wanted changesets. If your repository has other heads you need to preserve, specify them too, as additional --rev Y arguments. For example:

 hg clone backup repo --rev X --rev Y

When you've cloned, verify that

 hg incoming -R repo backup

really only shows the changesets you wanted to drop. If you discover changesets you do need, after all (for instance, another head you forgot to specify above), you can pull them over using

 hg pull -R repo backup --rev Y

Repeat until you're satisfied with the pruned repo.

Copy over all non-tracked files you might want to preserve. In particular, you might want to copy .hg/hgrc from the backup since your default path now points to the backup instead of the original clone source.

You can remove your backup repository now.

Compared to GIT

There’s one more big difference between Mercurial’s branching and git’s branching:

Mercurial will push/pull all branches by default, while git will push/pull only the current branch.

This is important if you’re a git user working with Mercurial. If you want to push/pull only a single branch with Mercurial you can use the --rev option (-r for short) and specify the tip revision of the branch:

$ hg push --rev branchname $ hg push --rev bookmarkname $ hg push --rev 4 

If you specify a revision, Mercurial will push that changeset and any ancestors of it that the target doesn’t already have.