开发者

Mercurial: back out last change so codebase is clean?

开发者 https://www.devze.com 2023-01-26 09:47 出处:网络
I\'ve just messed something up in Me开发者_StackOverflow中文版rcurial. How do I back out the last change so that the codebase is clean - specifically so that if someone else does \'hg pull\', they\'l

I've just messed something up in Me开发者_StackOverflow中文版rcurial.

How do I back out the last change so that the codebase is clean - specifically so that if someone else does 'hg pull', they'll have a working codebase?


Two ways:

hg rollback as mentioned by Fred; if you've already pushed, too late. hg rollback is only suitable for local use. hg strip (also as mentioned by Fred) works the same way and is (excepting its support for backing up) equivalent to doing hg rollback a number of times, till you get back to that revision.

hg backout for when you have already pushed and just want to revert the effects of the commit (if you've accidentally pushed out sensitive data, you'll need to take more drastic measures, but if you just want it to work, use this).

If the commit is not the last-committed revision, say so and we can get into deeper stuff (or search - it's been answered before).


Another way is to clone from a specific revision. Say checkin 6 was the mistake. You can clone your repository up to revision 5:

hg clone -r 5 myrepobad myrepoclean

now in myrepoclean you are back to where you were before the bad checkin. Obviously you need to be aware that anyone who has pulled the bad checkin is now liable to push it back in.


$ hg rollback --help
hg rollback

roll back the last transaction (dangerous)

    This command should be used with care. There is only one level of rollback,
    and there is no way to undo a rollback. It will also restore the dirstate at
    the time of the last transaction, losing any dirstate changes since that
    time. This command does not alter the working directory.

...

You should also look at the strip command.

0

精彩评论

暂无评论...
验证码 换一张
取 消