如何回滚 Mercurial 中的单个更改?
我对我的 Mercurial 项目中的一个文件进行了更改,我想回滚该文件,但我想保留随后发生的一些更改:
Revision 1: Original
Revision 2: A change I made in error
Revision 3: A change I want to keep
我只想回滚修订版 2 中的更改,留下 1 和3 应用,并创建一个新的修订版本 4. 最“Mercurial”的方式是什么?
请注意,是的,我可以从修订版 2 中提取反向差异并将其作为补丁应用到我的工作副本,然后提交。我知道。但我想找到该工具直接支持的某种方式。
I made a change to a file in my mercurial project that I'd like to roll back, but I'd like to keep some changes that occurred subsequent to it:
Revision 1: Original
Revision 2: A change I made in error
Revision 3: A change I want to keep
I want to roll back ONLY the changes in Revision 2, leaving 1 and 3 applied, and create a new revision 4. What is the most "Mercurial" way of doing that?
Note that yes, I could extract the reverse diff from revision 2 and apply it to my working copy as a patch, and commit that. I know. But I'd like to find some way that the tool directly supports.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为,如果您查看项目的变更日志(以便您可以看到所有修订),您可以选择一个修订并使用 backout 命令来撤消它。
(我手头没有任何东西可以检查这一点,所以它可能不正确。)
I think that if you view the changelog for the project (so that you can see all of the revisions), you can pick a single revision and use the backout command to undo it.
(I don't have anything at hand to check this, so it may be incorrect.)
您也可以使用 mq 补丁来编辑最近的历史记录。以下命令序列可以解决这个问题:
这种事情非常适合修复本地存储库中的错误,但由于您正在更改历史记录,因此请确保您没有推送给某人否则(或者他们没有从您那里获取)修复之前的原始版本。
如果我理解正确的话,
hg backout
将提交一个新的补丁来逆转之前的更改,从而将更改保留在您的历史记录中。这是一个更安全的选择,但如果你经常犯局部错误(像我一样),那就不太好了。You can use mq patches to edit your recent history as well. The following sequence of commands would do the trick:
This sort of thing is great for fixing up a mistake in your local repository, but since you're changing history, make sure you didn't push to someone else (or they didn't pull from you) the original version before you fixed it.
If I understand correctly,
hg backout
will instead commit a new patch which reverses the earlier change, thus keeping the change in your history. It's a safer option, but less nice if you make local mistakes often (like me).