How to merge to get rid of head with Mercurial command line, like I can do with TortoiseHg?

According to TortoiseHG's source, when you check Discard all changes from merge target (other) revision, it uses the hg debugsetparents command:

hg debugsetparents REV1 [REV2]

manually set the parents of the current working directory

    This is useful for writing repository conversion tools, but should be used with care.

    Returns 0 on success.

use "hg -v help debugsetparents" to show global options

To use:

    hg up <revision-to-keep>
    hg debugsetparents <revision-to-keep> <revision-to-throw-away>
    hg commit -m "Merge to discard ..."

If you don't want to use debugsetparents, you can manually revert to the changeset you want to keep before committing:

hg merge --tool internal:local -r HEAD_YOU_WANT_TO_DISCARD
hg revert -r 'tip^'
hg commit

Note, however, that this technique is not necessarily the best approach. You may be better off just closing the head:

hg up HEAD_YOU_WANT_TO_DISCARD
hg commit --close-branch

The documentation here is a little misleading; this only closes the specific head, not the entire branch.