Mercurial undo last commit

后端 未结 8 766
既然无缘
既然无缘 2020-12-02 06:11

How can I undo my last accidentally commited (not pushed) change in Mercurial?

If possible, a way to do so with TortoiseHg would be prefered.

Update<

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 06:22

    hg strip will completely remove a revision (and any descendants) from the repository.

    To use strip you'll need to install MqExtension by adding the following lines to your .hgrc (or mercurial.ini):

    [extensions]
    mq =
    

    In TortoiseHg the strip command is available in the workbench. Right click on a revision and choose 'Modify history' -> 'Strip'.

    Since strip changes the the repository's history you should only use it on revisions which haven't been shared with anyone yet. If you are using mercurial 2.1+ you can uses phases to track this information. If a commit is still in the draft phase it hasn't been shared with other repositories so you can safely strip it. (Thanks to Zasurus for pointing this out).

提交回复
热议问题