Is there any way to delete local commits in Mercurial?

后端 未结 10 1020
小鲜肉
小鲜肉 2020-11-28 19:11

So I keep making a silly mistake in Mercurial. Often times, I\'ll start work without doing an \"hg pull\" and an \"hg update.\" When I try to push my changes, I get an err

10条回答
  •  粉色の甜心
    2020-11-28 20:04

    Enable the "strip" extension and type the following:

    hg strip #changeset# --keep
    

    Where #changeset# is the hash for the changeset you want to remove. This will remove the said changeset including changesets that descend from it and will leave your working directory untouched. If you wish to also revert your committed code changes remove the --keep option.

    For more information, check the Strip Extension.

    If you get "unkown command 'strip'" you may need to enable it. To do so find the .hgrc or Mercurial.ini file and add the following to it:

    [extensions]
    strip =
    

    Note that (as Juozas mentioned in his comment) having multiple heads is normal workflow in Mercurial. You should not use the strip command to battle that. Instead, you should merge your head with the incoming head, resolve any conflicts, test, and then push.

    The strip command is useful when you really want to get rid of changesets that pollute the branch. In fact, if you're in this question's situation and you want to completely remove all "draft" change sets permanently, check out the top answer, which basically suggests doing:

    hg strip 'roots(outgoing())'
    

提交回复
热议问题