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

好久不见. 提交于 2019-11-28 05:45:41
jamessan

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!