How to revert a Mercurial hg pull?

对着背影说爱祢 提交于 2020-01-12 07:01:35

问题


If you do an hg pull and then an hg update (or an hg merge), is there a way to back this out? Ie: revert your repository to the state prior to doing the hg pull?

I believe you can do hg update -r n where you would specify the changeset prior to the pull as n. Though I'm guessing this will still leave the changesets in your repository but this isn't really what we want. ??


回答1:


hg strip will remove revisions from a repository. Like all powerful commands, its dangerous, so be careful.

https://www.mercurial-scm.org/wiki/StripExtension

Also see:

https://www.mercurial-scm.org/wiki/EditingHistory

If you catch your mistake immediately (or reasonably soon), you can just use hg strip REV to roll back the latest (one or more) changes. ...




回答2:


Ok, you can't rollback because you've done a commit. What you can do is use 'hg strip' which is part of mq (after 2.8 strip is in it's own extension), or use mq to remove the changes. Either way I suggest you do everything on another clone, just in case.

To do strip, update to a revision that you want to keep, and then

hg strip <REV>

where <REV> is the first revision you want to remove. It will remove that one and all decendents (including your merge commit).

Alternatively you can

hg qnew (if you don't already have a patch queue)
hg qimport <REV>

which will import a single revision into the patch queue. You can then add more, and then use the mq commands to edit, rearrange, delete, or whatever you want to do with those revisions. qdel deletes the current patch.


Edit: Obviously, you'll need to enable the MQ extension for both of these, unless you're using 2.8 or later. In that case strip is in the strip extension, and mq in the mq extension. Both are shipped with the standard installation.




回答3:


hg --rollback can be used to undo the last transaction so as long as your hg pull is still the most recent transaction then you can use that. This command should be used with care though. See here for some more details.




回答4:


you can:

hg update -C <version>

see the mercurial FAQ.




回答5:


If you want to remove all traces of the pull form your history then you need to use an extension as Bert F suggests (the philosophy in mercurial is to never change history)

if you dont mind history containing your mistake you have two slightly different options hg update -C -r which will create a new branch at the version you specify or hg revert -r which will stay on the same branch but create a new uncommited change undoing everything.



来源:https://stackoverflow.com/questions/4784265/how-to-revert-a-mercurial-hg-pull

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