1. 59

I recently started looking at hg after using git for years, for no other than curiosity when a friend said he was using it as well. I also am a believer in the argument that we should avoid a monoculture and clearly git is incredibly popular, so I should do my part.

I’ve been using hg on some personal projects for the last few weeks and here are my thoughts.

Simpler

So far hg is much simpler than git. The help page for a command generally fits on one terminal screen just fine. I generally haven’t required going to stackoverflow and copy and paste some magic to solve every problem.

That being said, I haven’t gotten myself into any crazy pickles that require doing wild things yet.

Branches vs Bookmarks

Coming from git it’s really hard for me to to tell when I want which. This might just be workflow confusion. hg is not just “git but different” it has its own style of development which I haven’t entirely grokked.

Branches

All of the documentation of hg makes one terrified of branches if they come from git. Should I make a branch to fix a typo? Is that bad? After asking some hg devs, they say that as long as you’re closing the branch upon merge one should be good. There are a few repos out there that need to really purge branches every few years due to performance issues but those are really far and few between.

hg convert

This is probably the smoothest software experience I’ve had ever. I converted a few git repos to hg repos with hg convert my-git-repo and it Just Worked. None of my repos are huge so maybe it breaks down on larger ones but this experience was great. Very low bar to just turn something into hg and start working on it.

BitBucket

Unfortunately the hosted hg situation is not super awesome. BitBucket is fine for hosting. And it seems like it’s also fine (although I haven’t tried) if you’re working with forks and creating PRs. However, if you’re used to a team working in one repo it’s less pleasant. It doesn’t really understand bookmarks very well so one cannot do PRs between bookmarks. Working with branches seems to be OK though. I hope BitBucket starts investing (again?) more in hg support.

Conclusion

For the stuff I’m doing, so far I like hg quite a bit. It’s just simpler and does things closer to how my brain expects it. For a project with many team members I will need to do some experiments and don’t have any such projects on the horizon. If one feels monocultures are worth pushing back against, I’d encourage you to start using it. As I said, I like it, but I am also willing to put up with the less-than-ideal situation for things like BitBucket just to use software I prefer.

  1.  

  2. 16

    I seem to be the only person who moved from git to mercurial and liked git a lot more.

    Here were my impressions:

    • The index (“staging area”) is an awesome feature. I know it trips people up occasionally, but the ability to carefully and precisely stage some of the changes in the working tree is invaluable.
    • I like git’s branch model better than Mercurial’s. It’s more flexible and, at least for me, more intuitive. Maybe bookmarks are equivalent, but we didn’t use them at my work, so I couldn’t say.
    • I like git’s general acceptance of history rewriting. It’s a valuable feature without which you need to choose between committing very carefully or breaking bisect and having a useless history. If you’re worried about corrupting your history, back up your repository (which you should do anyway, history rewriting is not the only way to corrupt a repository). I know it’s possible in Mercurial, but it’s not a first-class citizen and the culture disapproves.
    • Mercurial’s commandline interface is a bit more uniform and predictable, but to be honest, this feels like a very weak benefit. If you’re using it professionally, muscle memory should basically mitigate the difference within at most a few weeks. Also, Mercurial’s interface certainly isn’t perfect, e.g. -l for commit limiting in hg log is wrong (it should be -n).
    1. 12

      index (“staging area”) is an awesome feature.

      hg commit --interactive or hg ci -i is essentially the same thing. What people generally like about the index/cache/staging-area (these were all official synonyms at one point) is the ability to selectively pick apart commits, not so much having an extra, semi-obligatory step between your code and the creation of a commit. With Mercurial’s curses interface, hg ci -i is pleasant and widely loved.

      If you really want a cache/index/staging-area, you can use hg ci -i --secret to start a secret staging commit and hg amend --interactive or hg am -i to keep adding to it. The --secret part is just to make sure it doesn’t get pushed accidentally. Once you’re ready to show the world your commit, hg phase --draft will turn it into a draft that you can share.

      I like git’s general acceptance of history rewriting.

      hg has this too, but better, and not as well-advertised: there’s a meta-history of what is being rewritten. This is called changeset evolution. The basic idea is that there are obsolescence markers that indicate which commit replace which other commit, so that history editing can be propagated in a safe, distributed fashion. No more need to force-push everything and then tell everyone who may have been following along to reset branches. Just push and pull and hg evolve will figure out where everything should be because it has more context.

      Mercurial’s commandline interface is a bit more uniform and predictable, but to be honest, this feels like a very weak benefit.

      My father, may he rest in peace, used to say that people can get used to everything except hunger. Sure, you can get used to git’s widely-derided UI. But why should you have to? If we can come up with a better UI, we should. Indeed, alternative git interfaces are their own cottage industry. Don’t downplay the problems that the git UI cause.

      1. 9

        hg commit --interactive or hg ci -i is essentially the same thing.

        No it’s not. I can (and frequently do) continue to mess with the working tree after adding changes to the index.

        hg has this too

        General, ecosystem-wide acceptance of history rewriting? Not in my experience. When I was using it, the general guidance seemed to be “don’t do that, but if you’re going to do it anyway, here’s how”, whereas guidance for git is more along the lines of “here are some things to be aware of when you do that, now have fun”. No remote solution I used would permit pushing rewritten history.

        The very page you linked to says that evolve is incomplete.

        To be clear, the workflow I’m looking to be enabled here is to commit and push extremely frequently—as often as I save, ideally—and then, once the feature is complete enough for review, squash all those mostly-useless commits together into a single or few meaningful ones. This lets me get both commits willy-nilly and meaningful, bisect-able history.

        But why should you have to?

        Because it took me like three days? “Not ideal” is a far cry from “compellingly bad”. I will certainly agree that git’s interface is not ideal, but Mercurial’s is not better enough to be a compelling feature on its own. (Also, I had to get used to Mercurial’s interface when I started a job that used it. Why did I have to?)

        1. 9

          No it’s not. I can (and frequently do) continue to mess with the working tree after adding changes to the index.

          Have you tried hg ci -i? Combined with hg am -i, it really is the same thing. Creating a commit is, pardon the pun, no commitment.

          The very page you linked to says that evolve is incomplete.

          It’s sadly in a state of perpetual beta, but so was Gmail for about five years and that didn’t stop a lot of people from using it from day one. Evolve is mostly feature-complete, just not completely polished to the usual hg standards.

          To be clear, the workflow I’m looking to be enabled here is to commit and push extremely frequently—as often as I save, ideally—and then, once the feature is complete enough for review, squash all those mostly-useless commits together into a single or few meaningful ones. This lets me get both commits willy-nilly and meaningful, bisect-able history.

          This is exactly what evolve is for. And people can even pull your commits before they’re squashed and if they pull again after you squashed, they won’t even see the difference in their workflow. Their copy of the commits will also be squashed without them needing to do an extra step like git reset and try to figure out exactly what to throw out.

        2. 4

          I agree that the staging area is an unnecessary concept. As a self experiment, I made myself git aliases to not use staging. After a few months of using that setup, I can say that I don’t miss staging.

          (I don’t use Mercurial at all)

          1. 3

            IMHO hg ci -i is a way better interface than git staging area even with -i. Used both, Mercurial one is way better.

            However I just recently found that there’s a mercurial equivalent of hg -i for git too as a plugin.

          2. 4

            what benefit does the staging area give you that cannot be replicated by just committing the changes you would have staged and then doing a rebase to squash all the ‘stage’ commits into one main commit? I use this workflow a lot and find the intermediate stages cleaner and easier to work with than the git staging area.

            1. 2

              The index feels cleaner and if I wander away in the middle and forget what I was doing, it’s much easier to unwind.

              Obviously, there are any number of workflows which provide equivalent functionality, and I doubt anyone can muster more than extremely weak objective support or criticism of any. Having used both git and mercurial, I strongly prefer having the index to not having it. If people push me on it, I’m sure I can rationalize that preference until the cows come home, but I’m not sure how constructive that would be.

          3. 7

            What hg calls “branches” are entirely different from git branches. They are generally meant to be permanent, and shouldn’t be used if no one else would ever want to pull them in. A good application of hg branches, would be to have a “dev” branch that merges into the “stable” branch from time to time.

            From here on out, when I say “branch” I mean it in the sense of a git branch.

            People often say “bookmarks” are the equivalent of git branches, but this is a bit misleading. Bookmarks are, very simply, a tag that automatically updates when it is activated and you make a new commit. A bookmark only knows the direct commit it is applied to, nothing more.

            So how do you create a “git-like” branch in mercurial? You update to any non-head revision and commit. This creates a new (unnamed) branch on the DAG. You can see it by running hg log -G, or better hg show work (after enabling the show extension in your hgrc). All bookmarks do are add a string label to these unnamed branches which can help you track them a bit better. They are not necessary to do branching however, many of my colleagues just use revision numbers and hg show work to keep track of it all.

            Finally, there is an experimental feature called “topics” being developed. It’s currently packaged in the “evolve” extension, so this needs to be installed separately. I won’t go into much detail on topics here, but they can enable more “git-like” branching workflows than heads + bookmarks can.

            1. 4

              Bookmarks are, very simply, a tag that automatically updates when it is activated and you make a new commit.

              Strictly speaking, this is exactly what a git branch is too: just a ref. People use the word “branch” in git loosely, though, to refer to both the ref and the commits reachable from that ref. Actually, most of the time people use it in the latter sense without having a firm grasp that the former is all that is happening.

              There are some UI ways in which git branch-refs are handled differently than hg-branches, for example, git calls a “merge” what may only be advancing a git branch-ref and has no merge-like qualities at all (i.e. no merging of files, thus no potential to resolve conflicts and certainly no merge commit). It is for this reason that hg merge does not advance bookmarks in hg and instead says that there is no merge to be done. Another UI difference is that git also has additional markers called remote branches that are another ref but one that is only moved by different parts of the UI i.e. push/pull/fetch commands.

              1. 2

                I’ve actually switched to describing classic Mercurial branches as “labels” to people coming from Git, and just telling them to use bookmarks and to always make a bookmark called @ when they start. That, combined with Bitbucket natively supporting obsolete markers, usually helps them get used to the Hg workflow more easily (since things like rebase now do what you’d expect and cleanly allow pushing with deprecation).

              2. 6

                I’ve actually switched to Mercurial at the studio after having used Git for years. I was already using Mercurial back in 2005 when Git had no user-friendly porcelain, but then switched to Git when GitHub appeared.

                The main surprise for me with Hg is that merges seem to happen more often and force you to commit while in Git most merges are automatic.

                The other main difference is the management of branches. In Git, branches can be short lived (1 branch per feature) while this is not recommended in Hg.

                However, Hg supports multiple heads (some of them named using bookmarks), which can be used in the same way as Git branches. In our workflow, we use one branch per developer for a project.

                The killer features for me are extensions like histedit and evolve, plus how easy it is to write custom extensions in Python.

                Overall I find the Hg command flow very natural and easier to use than Git, especially for more advanced cases. The Wiki documentation is also a great resource and contains interesting insights into how Hg works.

                It also seems to me that the Hg is more innovative than Git: the recent introduction of markers to support clean history rewrites is quite smart and interesting. It shows that DVCS is still an active research field where there is room for experimentation.

                After almost a year with Hg, I’m very happy with the change. If I would sum up why Hg feels better it is that complex tasks seem easier to do than with Git.

                1. 6

                  One of the biggest differences is design philosophy. Like you noticed, mercurial is much simpler than git by default. This is largely because many of the features are hidden behind extensions (built-in or otherwise) or config options. Mercurial, when configured for it, is every bit as powerful as git.

                  Concepts I’d highly recommend familiarizing yourself with are: DAG, phases, revsets, templates, changeset evolution

                  Built-in extensions I recommend include: rebase, purge, pager, shelve, show, color, progress, histedit, fsmonitor

                  External extensions: evolve (this is an official one, highly recommended), absorb, bookbinder

                  I sort of liken hg to vim and git to atom. Tweaking mercurial to your liking takes a lot of time and effort, but is well worth the effort in the long run.

                  1. 4

                    If you don’t need hosted option but on-premise/private cloud you can check out RhodeCode which supports bookmark based Pull requests, Pull Request versioning, Mercurial evolve support.

                    Here’s our blog post on how to use bookmarks via Pull requests: https://rhodecode.com/blog/120/mercurial-workflow-using-bookmarks-how-to-setup-and-use

                    From our perspective using Mercurial to develop RhodeCode, a bookmark based workflow is a much easier to use than branches. And evolve/phases make it easier to simply rebase/reorder your commits, or fix small problems found during code-review.

                    1. 2

                      Glad to hear you’re enjoying Mercurial. Because I’m curious how they feel to a recent Git user: how do you like having local commit numbers that go 1, 2, 3, ... beside the usual unique hashes?

                      1. 3

                        I don’t use it that much but it is kind of nice to have a short hand, linear, way to look at the commits. Just talking about hash’s is pretty useless for anything other than knowing they aren’t the same.

                        1. 2

                          It’s nice to hear that you enjoy rev numbers, too. They are a detail, but one that I am fond of.

                        2. 2

                          Those numbers come in handy. E.g hashes don’t give you a perspective, you can tell quickly how big the project is looking at the numeric number, also comparing abcd...efgh vs 10...20 gives you much easier syntax to understand. Ofcourse this all applies only to local repositories because those numbers are relative

                        3. 1

                          No complaints? They sucks about the limited hosting options. Awesome report!

                          1. 1

                            I know that Github was mentioned, but what about the ecosystem support of other extensions?

                            I think that’s a major factor holding people to Git/Github.

                            It’s an interesting idea that an easier to use VCS might also encourage more project involvement.

                            1. 3

                              You can have a local Hg repo and push/pull to GitHub no problem.

                              1. 1

                                Could you go into a bit of detail on the best practice/most solid way to use Hg locally with a Github repo?

                                1. 1

                                  I’ve been using hg-git with great success. I haven’t used it for much other than making branches (hg bookmarks in this case) and pushing them and merging them, but I’ve been really surprised how well things work. One reason I like it is because some operations in git that I felt were a bit ad-hoc, like squashing commits via an interactive rebase, are a simpler and safer experience in hg with the evolve plugin. Just hg fold --from .... I haven’t tried making tags or signing commits, but for what I’m doing this simpler workflow seems to work fine.