hg equivalent of git push -f?

Jeremy . voldermort at hotmail.com
Tue Mar 7 08:26:14 UTC 2017


> I've been thinking of what it would take to convert my work place from
> git to hg, and the one thing which doesn't seem to have any equivalent
> is git push -f. hg may also have a push -f, but it leaves dangling
> anonymous heads which have to be stripped on the server. Evolve may
> help, but it doesn't like changing branches which have been pushed to
> a publishing repository, and we don't need or want the overhead of
> keeping obsolete changesets and markers.

>One solution is already in there: You can make the remote repository
>non-publishing. The obsoletes do not leave that server.

>   # with evolve
    cd /tmp
    hg init moo
    cd moo
    echo 1 > 1
    hg ci -Am 1
    echo 2 > 1
    hg ci --amend -Am 1
    hg log --hidden
    # three changesets
    cd ../
    hg clone moo goo
    cd goo
    hg log --hidden
    # only the final changeset

The clones don't have the obsolete clutter, but the original repo and the server do. I suspect that there would be resistance to this, although I don't know how much of an issue it would be in practice.

Making the repository non-publishing is interesting, because what we really want is to state that only certain branches are publishing. GitHub & Bitbucket allow something like this with branch protections, but as far as I know no vcs has this build in (other than the possibility of doing it yourself with hg hooks).

>Alternatively you could create a push hook which automatically strips
>the old changesets. The following example is for bookmarks, but you
>could also just strip away the non-tip head on a force-push.

>[hooks]
>pushkey.delete-old-history = if test x"$HG_NAMESPACE" = x"bookmarks"; then $HG strip --hidden -r "::$HG_OLD - ::$HG_NEW"; hg update $HG_KEY; fi

This would give the same workflow as git, other than that they are moved immediately to a backup file instead of being hidden until GC. I wonder if it could be done as an extension?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial/attachments/20170307/3ac97cb3/attachment.html>


More information about the Mercurial mailing list