Hacker News new | ask | show | jobs
by howinteresting 1525 days ago
Basically none of this post is true. History in Mercurial is thoughtfully mutable (much more than Git) with public and draft phases; hg backout is part of the base distribution; it fully supports the PR model and better ones like stacked diffs. Ultimately it lost because of GitHub, but it lives on as Fig at Google and Eden at Facebook (both of which heavily use mutable history, of course).
2 comments

Talking about flexible mutable history, there are two more official extensions to be mentioned:

- evolve [0], which allows to rewrite history lossessly (without ever risking losing data)

- absorb [1] which takes uncommitted working copy changes, and for each hunk finds the last commit that touched those lines, and rewrites it. It's an extension originally from Facebook, in core since 2018. Works like magic: no "fix" commits ever more.

Plus, all of this is available using mercurial locally and interacting with git (and github) remotely, via hg-git. Admittedly, this requires to be a bit of an advanced user, but the gains in ergonomics are tangible.

[0] https://www.mercurial-scm.org/doc/evolution/

[1] https://gregoryszorc.com/blog/2018/11/05/absorbing-commit-ch...

It is kind of true, though. From Mercurial docs:

>The public phase holds changesets that have been exchanged publicly. Changesets in the public phase are expected to remain in your repository history and are said to be _immutable_

Note that in Git all history is mutable, even if published.

Regarding 'backout' (and 'revert'), to the best of my knowledge, it does not revert commit, it creates a new one (reverting changes), and I frankly do not know is that's possible at all to amend commit in Mercurial (when I worked with it, that was definitely not possilbe, but that was a long time ago)

In Mercurial all history is mutable too, there's just a UI failsafe that prevents you from mutating public history unless you manually override it. Git is just plain bad in this regard.

hg backout is like git revert. Creating a new commit is correct if you want to e.g. propagate the change through continuous deployment.

And hg commit --amend has existed for a long time.

Git has "reset" in addition to "revert" (the former mutates history but the latter does not). What Mercurial has for removing the wrong commit?

For amend option - well, we switched to Git at time of Mercurial 2.1 (I said it was long time ago), did not notice they added this feature, sorry.

git reset does like 25 different things.
that would be `hg prune` in modern Mercurial.
You can do

> hg commit --amend

to change the topmost commit.

Marking commits as public is mostly a safeguard against accidentally altering history that others may already depend upon. This is just there to provide awareness of the giant footguns hiding when editing history after it has been shared (git contains the same footguns without safeguards). You can revert the status of a commit from public to draft and then change it. Just like in git, it's very dangerous to do so, but hg makes it very obvious. The command is

> hg phase --draft --force .

On top of that, there is the notion of change set _obsolescence_: a change may be replaced by a newer one, effectively replacing it.