问题描述
我了解回滚的限制,并了解使用所需的护理,但是我只是想知道为什么只有一个级别的回滚.
I understand the restrictions of rollback and the care required in its use, but I just wondered why there is only one level of rollback.
我猜这是一个设计决定,而且存储多个先前的事务状态以处理多个级别的回滚的麻烦比它的价值还要麻烦.
My guess it's a design decision and that the hassle of storing multiple previous transactional states to handle multiple levels of rollback is more trouble than its worth.
推荐答案
回滚只有一个级别,因为回滚从来都不是真正的功能.回滚是存在的,并且具有奇怪的名称,因为回滚起源于Mercurial的commit/push/pull事务系统.
There's only one level of rollback because rollback was never really intended as a feature. Rollback exists, and has it's odd name, because it grew out of mercurial's commit/push/pull transaction system.
如果要进行网络推送,并且完成了99%,然后连接断开,则不应将存储库置于不一致的状态.为了确保可以丢弃不完整的更改,在完成任何写操作之前会创建一个发生任何事情之前"的指针,如果更改被中止,则所有内容都将重置为该状态-回滚.
If a network push is coming in and it gets 99% done and then the connection is lost the repository shouldn't be left in an inconsistent state. To make sure that an incomplete change can be discarded a "before anything happened" pointer is created before any writes are done and if the change is aborted everything is reset to that state -- rolled back.
rollback
命令实际上只是在成功完成之后使先前的操作失败".在设计了必要的交易安全性之后,这只是免费".
The rollback
command is really just "failing" the previous operation after it had successfully completed. It's just something that "came free" after necessary transactional security was designed in.
使用类似控制钩子可以定义必须通过的检查/测试,才能成功完成推送或提交.为了无法成功完成,必须可以撤消进行中的提交,但这也不需要多个级别.
When using something like a controlling hook one can define checks/tests that must be passed in order for a push or commit to complete successfully. In order to not-complete successfully it must be possible to undo that in progress commit, but that doesn't require multiple levels either.
由于VonC正确地指出了回滚可能非常危险.许多人回滚他们已经推送的更改,然后在其他更改随后又拉回时变得非常困惑. hg backout
命令几乎总是一个更好的主意.
As VonC correctly notes rollback can be pretty dangerous. Many a person rollsback changes they've already pushed and then gets very confused when other those changes come back on subsequent pulls. The hg backout
command is almost always a better idea.
还请注意,您可以通过执行以下操作轻松模拟到任何时间点的回滚:
Note also that you can simulate a rollback to any point in time easily by doing this:
hg clone -r last_revision_I_want repo_with_things_I_do_not_want new_repo_with_only_good_stuff
这篇关于为什么Mercurial仅具有一个回滚级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!