Mercurial's default hg log
has a different philosophy than git log
. Where git log
shows you a relative view of history from your current working directory or specified revision, Mercurial's log
command by default shows a global view of history in your repository. In a small project, I can imagine that making sense, but to be honest, 95% of the time I find hg log
does the wrong thing for what I want. So:
[alias]
flog = log -f --template=wip
Adds hg flog
as an alias for following-log, which is closer in behaviour to the git log. The --template-wip
bit uses the colourization and line formatting already provided for the wip
extension.
Honestly though, I use hg wip
about 10x more often than I use hg {f}log
.
Phases
One of the cool things about Mercurial is its well developed reasoning about history rewriting. One key element to that is the notion of 'phases' which help define when a rewrite of a changeset can happen. There's a darn good chance this will be a sensible default for you in your .hgrc
:
[phases]
publish = false
Getting to work
I use a clone of mozilla-unified
as the starting point. When I start working on something new, unless I have a good reason not to, I'll typically start work off of the most recent central
tag in the repo.
$ hg pull && hg up central
Labelling (Bookmarks)
When working in Mercurial, one of the things you get to decide is whether or not you label you commits or not. This article goes into more detail, but suffice it to say, there's no requirement, as there is in in git, to label your lightweight branches (using Bookmarks).
I have experimented both with labelling and not these days, and I have to say, so long as I have hg wip
, I think it's pretty reasonable to get by without bookmarks, especially as my commit messages typically end up having the bug numbers in them, so it feels almost like redundant info to label the branch. Maybe if you work on a project where commit messages aren't associated with a bug or other identifier labelling might be more useful.
When developing, I tend to use commits as checkpoints. Then later, what I will do is use history rewriting tools to create the commits that tell the story I want to tell. In Mercurial, this means you'll want to enable the Evolve and Histedit extensions (Facebook's chistedit.py
is also nice, but not necessary). You'll also want rebase
(unlike in git, rebase
and histedit
are two distinct operations).
A tip with histedit
: When I first started with mercurial, I found myself more uncomfortable with histedit
than I was with git. This was because I was used to doing 'experimental' history editing, always knowing I could get back to the repo state I stared from just by moving my branch pointer back to the commit I left behind.
Mercurial, with the evolve extension enabled, has a more complicated story for how history editing works. Over time, you'll learn about it, but in the mean time, if you want to be able to keep your old history: hg histedit --keep
will preserve the old history and create the new history under a new head.