如何删除 Mercurial 中的提交?
我想完全删除 Mercurial 提交,就好像它从未输入到存储库中一样,然后移回我之前的提交。
这可能吗?
I want to completely delete a Mercurial commit as if it was never entered in the repository and move back to my prior commit.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
如果这是您的最后一次提交并且您尚未将其推送到任何地方,则可以使用
回滚
来执行此操作。否则,不行。并不真地。是时候更改密码了。编辑:有人指出,您可以从旧版本克隆并合并您想要保留的更改。这也是事实,除非您将其推送到您无法控制的存储库。一旦你推送,你的数据很可能很难恢复。
If it was your last commit and you haven't pushed it anywhere, you can do that with
rollback
. Otherwise, no. Not really. Time to change your passwords.Edit: It has been pointed out that you can clone from an older revision and merge in the changes you want to keep. That's also true, unless you have pushed it to a repo you don't control. Once you push, your data is very likely to be very hard to get back.
您可以尝试删除有关您的提交的 mq 信息。
修改历史记录->删除
You can try to remove mq info about your commit.
ModifyHistory->Strip
要编辑历史记录,我将使用 Histedit Extension 扩展。
但是请记住,这仅在您尚未将提交推送到公共存储库、您拥有公共存储库和/或您可以负责所有克隆的情况下才有意义。如果您收到以下错误:
这意味着 Mecurial 认为这是一个公共变更集(请参阅阶段)已经被推送了 - 您可以再次将其强制为
草稿
:To edit the history I would use the Histedit Extension extension.
However keep in mind this only makes sense in a situation where you have not yet pushed the commits to the public repository, you own the public repository and/or you can account for all the clones out there. If you receive the following error:
It means that Mecurial thinks this is a public changeset (see phases) that has already been pushed - you can force it to be a
draft
again doing:我经常遇到这种情况。我进行提交,然后进行拉推。但随后发生了一些事情,使得我新做出的提交变得不必要。简单的
hg 回滚
是不够的,因为它只会撤消拉动...这就是要做的事情:
当您不将变更集推送到任何地方时,事情就不会那么痛苦。
I encounter this fairly often. I make a commit and then pull to push. But then there is something incoming that makes my newly made commit unnecessary. A plain
hg rollback
isn't enough because it only undoes the pull...This is the thing to do:
Things are painless when you don't push your changesets anywhere.
如果有多个提交和/或您已经将其推送到其他地方,您可以克隆您的存储库并指定应克隆的最后一个变更集。
请参阅我的回答,了解如何执行此操作:
Mercurial:修复中断的历史记录
如果您只在本地提交并且没有推送,那么您可以在本地创建一个克隆(如我的链接中所述),然后就完成了。
如果您已经推送到某个远程存储库,则必须将其替换为您的克隆。
当然,这取决于您是否能够(或允许)这样做。
If it's more than one commit and/or you already pushed it somewhere else, you can clone your repository and specify the last changeset that should be cloned.
See my answer here how to do this:
Mercurial: Fix a borked history
If you only committed locally and didn't push, you can just create a clone locally (as described in my link) and you're done.
If you already pushed to some remote repository, you would have to replace that with your clone.
Of course it depends if you are able (or allowed) to do this.
您基本上可以使用“hg backout”进行反向合并。所有选项均在免费提供的书籍“Mercurial:权威指南”中进行了讨论:
http://hgbook.red-bean.com/read/finding-and-fixing-mistakes.html
You can use "hg backout" to do a reverse merge basically. All options are discussed in the freely available book "Mercurial: The Definitive Guide":
http://hgbook.red-bean.com/read/finding-and-fixing-mistakes.html
如果使用乌龟,您可以使用修改历史记录>条...
If using tortoise you can use modify history > strip...
是的。除非我弄错了,从 v2.3 (rel. 2012/08/01) 开始,您可以使用 HisteditExtension 和
drop
命令来删除提交,以及 < code>strip 或backout
以删除更改。对该功能进行简单的 Google 搜索:https://www.google.com/webhp#q =histedit+drop
Yes. Unless I am mistaken, as of v2.3 (rel. 2012/08/01) you can use the HisteditExtension with a
drop
command to drop a commit, along withstrip
orbackout
to remove changes.A simple Google search on the feature: https://www.google.com/webhp#q=histedit+drop
2022 年,我确实使用 <代码>进化扩展。它是实现此目的的最佳扩展之一。
要
修剪
不需要的变更集,例如,如果您进行了快速修改以使代码正常工作:现在您有了适当的补丁,您可以执行
hg prune。
:如果您推送更改到远程存储库时,您只会发现
obsoleasing
标记:要检查本地存储库的更改,您可以从远程存储库
pull
:In 2022 I do use
evolve
extension. It is one of the best extensions for this purpose.To
prune
unwanted changeset, if you for example did a quick hack to get the code working:Now you have a proper patch you can do
hg prune .
:If you push the change to the remote repository you will find only
obsolescence
markers:To check the changes to your local repo you can
pull
from the remote one: