如何删除 Mercurial 中的提交?

发布于 2024-10-18 16:01:33 字数 68 浏览 2 评论 0原文

我想完全删除 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 技术交流群。

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

发布评论

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

评论(9

墨洒年华 2024-10-25 16:01:33

如果这是您的最后一次提交并且您尚未将其推送到任何地方,则可以使用回滚来执行此操作。否则,不行。并不真地。是时候更改密码了。

编辑:有人指出,您可以从旧版本克隆并合并您想要保留的更改。这也是事实,除非您将其推送到您无法控制的存储库。一旦你推送,你的数据很可能很难恢复。

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.

烙印 2024-10-25 16:01:33

您可以尝试删除有关您的提交的 mq 信息。

  • 为此,您需要转到“文件”->“设置”->“扩展”。
  • 检查 mq 并重新启动 gui。
  • 之后只需右键单击不需要的提交并
    修改历史记录->删除

You can try to remove mq info about your commit.

  • For this you need to go File->Settings->Extensions.
  • There check mq and restart gui.
  • After that just right click on unneeded commit and
    ModifyHistory->Strip
中二柚 2024-10-25 16:01:33

要编辑历史记录,我将使用 Histedit Extension 扩展。

 hg histedit 45:c3a3a271d11c

但是请记住,这仅在您尚未将提交推送到公共存储库、您拥有公共存储库和/或您可以负责所有克隆的情况下才有意义。如果您收到以下错误:

abort: can't rebase immutable changeset 43ab8134e7af

这意味着 Mecurial 认为这是一个公共变更集(请参阅阶段)已经被推送了 - 您可以再次将其强制为草稿

hg phase -f -d 45:c3a3a271d11c

To edit the history I would use the Histedit Extension extension.

 hg histedit 45:c3a3a271d11c

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:

abort: can't rebase immutable changeset 43ab8134e7af

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 phase -f -d 45:c3a3a271d11c
溇涏 2024-10-25 16:01:33

我经常遇到这种情况。我进行提交,然后进行拉推。但随后发生了一些事情,使得我新做出的提交变得不必要。简单的 hg 回滚 是不够的,因为它只会撤消拉动...

这就是要做的事情:

hg strip <rev>

当您不将变更集推送到任何地方时,事情就不会那么痛苦。

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:

hg strip <rev>

Things are painless when you don't push your changesets anywhere.

心的憧憬 2024-10-25 16:01:33

如果有多个提交和/或您已经将其推送到其他地方,您可以克隆您的存储库并指定应克隆的最后一个变更集。

请参阅我的回答,了解如何执行此操作:
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.

一场信仰旅途 2024-10-25 16:01:33

您基本上可以使用“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

多情出卖 2024-10-25 16:01:33

如果使用乌龟,您可以使用修改历史记录>条...

If using tortoise you can use modify history > strip...

并安 2024-10-25 16:01:33

是的。除非我弄错了,从 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 with strip or backout to remove changes.

A simple Google search on the feature: https://www.google.com/webhp#q=histedit+drop

羁客 2024-10-25 16:01:33

2022 年,我确实使用 <代码>进化扩展。它是实现此目的的最佳扩展之一。

修剪不需要的变更集,例如,如果您进行了快速修改以使代码正常工作:

$ echo 'debug hack' >> file1.c
$ hg commit -m 'debug hack'

现在您有了适当的补丁,您可以执行hg prune。

$ hg prune .
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
working directory is now at 2a39221aaebb
1 changesets pruned

如果您推送更改到远程存储库时,您只会发现obsoleasing 标记:

$ hg push
searching for changes                          
no changes found                               
remote: 1 new obsolescence markers             

要检查本地存储库的更改,您可以从远程存储库pull

$ hg pull                            
pulling from ssh://userid@server/repo
searching for changes      
no changes found

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:

$ echo 'debug hack' >> file1.c
$ hg commit -m 'debug hack'

Now you have a proper patch you can do hg prune .:

$ hg prune .
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
working directory is now at 2a39221aaebb
1 changesets pruned

If you push the change to the remote repository you will find only obsolescence markers:

$ hg push
searching for changes                          
no changes found                               
remote: 1 new obsolescence markers             

To check the changes to your local repo you can pull from the remote one:

$ hg pull                            
pulling from ssh://userid@server/repo
searching for changes      
no changes found
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文