Mercurial:取消最后的更改以便代码库干净?

发布于 2024-10-03 07:24:13 字数 94 浏览 3 评论 0原文

我刚刚在 Mercurial 中搞砸了一些事情。

我如何取消最后的更改以使代码库干净 - 特别是如果其他人执行“hg pull”,他们将拥有一个可用的代码库?

I've just messed something up in Mercurial.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

↘人皮目录ツ 2024-10-10 07:24:13

两种方式:

hg rollback 正如 Fred 提到的;如果你已经推动了,那就太晚了。 hg rollback 仅适合本地使用。 hg strip (也如 Fred 所提到的)的工作方式相同,并且(除了它对备份的支持之外)相当于多次执行 hg rollback ,直到你得到回到那个修订版。

hg backout 适用于当您已经推送并且只想恢复提交的效果时(如果您不小心推送了敏感数据,则需要采取更多措施)严厉的措施,但如果你只是想让它发挥作用,请使用这个)。

如果提交不是最后提交的修订版,请这么说,我们可以进入更深入的内容(或搜索 - 之前已经回答过)。

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).

蓬勃野心 2024-10-10 07:24:13

另一种方法是从特定版本克隆。说 checkin 6 是错误的。您可以将存储库克隆到修订版 5:

hg clone -r 5 myrepobad myrepoclean

现在在 myrepoclean 中,您将回到错误签入之前的位置。显然,您需要意识到,任何拉出错误签入的人现在都有可能将其推回。

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.

﹂绝世的画 2024-10-10 07:24:13
$ 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.

...

您还应该查看 strip 命令。

$ 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文