放弃更改而不从历史记录中删除

发布于 2024-09-19 02:03:14 字数 229 浏览 11 评论 0原文

有一个提交不起作用,所以我想放弃它而不将其从历史记录中删除

我已经从早期的修订版中进行了更新并提交,从而创建了一个新的头。


我没有分支,我不想要分支,我只想简单地继续使用新的头,就像它原来的样子,没有什么花哨的,没有合并,没有担心,只是继续忘记前一个。

我似乎无法找到如何做到这一点,并且我开始相信这是不可能完成的。我发现的只是关于分支的东西,或者关于合并的东西。

There is a commit that just didn't work, so I want to abandon it without deleting it from history.

I have updated from an earlier revision and committed, thus creating a new head.


I don't have branches, I don't want branches, I just want to simply go on with the new head exactly as it is, nothing fancy, no merge, no worries, just go on forgetting the previous one.

I can't seem to find how to do that, and I'm starting to believe it can't be done. All I find is stuff about branches, or stuff about merging.

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

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

发布评论

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

评论(9

怪我入戏太深 2024-09-26 02:03:15

我知道您在这个阶段不想与分支机构合作,但这正是您所做的。当您返回到早期版本并提交一些有效的内容时,您创建了一个分支 - 一个未命名的分支,但仍然是一个分支。


照原样继续下去,不用担心有多个头,这没有问题,但如果你想整理一下东西,这样你就不会意外地选择错误的头,那么你可以杀死旧的分支。

Mercurial 文档中有一个很好的部分,它带您了解有关修剪死枝。

我认为对您来说最好的选择是将旧分支标记为“已关闭”。如果您的旧头版本是“123”,那么:

hg update -r 123
hg commit --close-branch -m 'Closing old branch'
hg update -C default

I know you don't want to work with branches at this stage, but that's exactly what you've done. When you went back to an earlier version and committed something that worked you created a branch - an unnamed branch, but a branch all the same.


There's no problem with just carrying on just as you are and not worrying about having multiple heads, but if you want to tidy things up so you don't accidentally pick the wrong head one time then you can kill off the old branch.

There's a good section in the Mercurial documentation that takes you through a number of options around Pruning Dead Branches.

I think the best option for you is to mark the old branch as "closed". If your old head is revision "123" then:

hg update -r 123
hg commit --close-branch -m 'Closing old branch'
hg update -C default
肥爪爪 2024-09-26 02:03:15

首先,输入:

hg heads

想象一下,您列出了三个头:

changeset:   223:d1c3deae6297
user:        Your name  <[email protected]>
date:        Mon Jun 09 02:24:23 2014 +0200
summary:     commit description #3

changeset:   123:91c5402959z3
user:        Your name <[email protected]>
date:        Sat Dec 23 16:05:38 2013 +0200
summary:     commit description #2

changeset:   59:81b9804156a8
user:        Your name <[email protected]>
date:        Sat Sep 14 13:14:40 2013 +0200
summary:     commit description #1

比方说,您希望保持最后一个头处于活动状态 (223) 并关闭其余的头。

然后,您将执行以下操作:

关闭头 #59

hg up -r 59
hg ci --close-branch -m "clean up heads; approach abandoned"

关闭头 #123

hg up -r 123
hg ci --close-branch -m "clean up heads; approach abandoned"

提交更改

hg push

不要忘记最后切换到右侧头

hg up -r 223

这样就完成了。

First of all, type:

hg heads

Imagine, you have three heads listed:

changeset:   223:d1c3deae6297
user:        Your name  <[email protected]>
date:        Mon Jun 09 02:24:23 2014 +0200
summary:     commit description #3

changeset:   123:91c5402959z3
user:        Your name <[email protected]>
date:        Sat Dec 23 16:05:38 2013 +0200
summary:     commit description #2

changeset:   59:81b9804156a8
user:        Your name <[email protected]>
date:        Sat Sep 14 13:14:40 2013 +0200
summary:     commit description #1

Let's say, you want to keep the last head active (223) and close the rest.

You would then do as follows:

Close head #59

hg up -r 59
hg ci --close-branch -m "clean up heads; approach abandoned"

Close head #123

hg up -r 123
hg ci --close-branch -m "clean up heads; approach abandoned"

Commit the changes

hg push

Don't forget to switch to the right head at the end

hg up -r 223

And you're done.

余生再见 2024-09-26 02:03:15

您想要使用hg backout。这将从任何子变更集中删除该变更集所做的更改。

看看这个有一个很好的解释。
Mercurial 取消

You want to use hg backout. This removes the changes made by the changeset from any child changeset.

Check this out for a good explanation.
Mercurial Backout

红玫瑰 2024-09-26 02:03:15

关闭或剥离不需要的分支的另一种方法是以完全丢弃其影响但将其留在历史中的方式合并它。这种方法将允许那些不需要的更改在推送中传播 - 因此仅当这是预期效果时才使用此方法。

假设变更集历史记录如下所示:

1-2-3-4-5-6    
       \    
        7-8-*

不再需要 56

您可以执行以下操作:

hg up 8
hg merge -r 6 -t :local
hg commit ...

这将创建以下内容:

1-2-3-4-5-6    
       \   \
        7-8-9-*

8 的更新可确保您在历史上您想要保留的所需位置上工作。

-t :local 指示 hg 使用名为 local 的合并“工具”,它告诉它忽略来自另一个分支的更改,即当前分支不代表的更改工作文件夹状态。 更多信息

因此,56 中不需要的更改会保留在历史记录中,但不会影响最近的任何内容。

An alternative to closing or stripping the unwanted branch would be to merge it in a way that totally discards its effects, but leaves it in history. This approach will allow those unwanted changes to propagate in a push - so only use this if that is the intended effect.

Let's say the changeset history looks like this:

1-2-3-4-5-6    
       \    
        7-8-*

and it is 5 and 6 which are no longer wanted.

You can do this:

hg up 8
hg merge -r 6 -t :local
hg commit ...

which will create this:

1-2-3-4-5-6    
       \   \
        7-8-9-*

The update to 8 ensures you are working at the desired head in history, which you want to keep.

The -t :local instructs hg to use the merge "tool" called local which tells it to ignore changes from the other branch, i.e., the one NOT represented by the current working folder state. More info.

Thus the unwanted changes in 5 and 6 are preserved in history but do not affect anything more recent.

丶情人眼里出诗心の 2024-09-26 02:03:15

尼尔和尼克的回答都很直接。因为我发现自己创建了很多悬空的头,所以我最终编写了一个别名来更轻松地关闭头。通过将其添加到您的 .hgrc 中:(

[alias]
behead = !REV=$($HG id -i); $HG update $@ -q && $HG ci --close-branch -m "Closing dead head" && $HG update $REV -q

如果您已经有 [alias] 部分,您可以附加到它)

您现在可以在一个单中关闭一个头 -命令(并且无需手动更新到不同的变更集)如下所示:

$ hg behead 123

注意:别名利用了以下事实: Mercurial 别名可以是 shell 命令。这意味着这可能只能在 UNIX 上运行,而不能在 Windows 上运行。

Both Niall's and Nick's answers are straight on. Because I find myself creating lots of dangling heads, I ended up writing an alias to close heads more easily. By adding this to your .hgrc:

[alias]
behead = !REV=$($HG id -i); $HG update $@ -q && $HG ci --close-branch -m "Closing dead head" && $HG update $REV -q

(if you already have an [alias] section, you can append to it instead)

You can now close a head in one single-command (and without having to update to a different changeset manually) like this:

$ hg behead 123

Note: the alias takes advantage of the fact that Mercurial aliases can be shell commands. This means that this will probably only work on UNIX, not on Windows.

み格子的夏天 2024-09-26 02:03:15

这是 Evolve 扩展 的用例。它目前未与 Mercurial 捆绑在一起,因此从技术上讲它是第三方扩展。但它被很多人大量使用,包括 Mercurial 开发人员,并且正在非常积极地开发,而且不会有任何发展。

有了 Evolve 扩展,您只需

hg prune -r revname

继续您的生活即可。 cset 仍然存在,但已过时。除非您将 --hidden 选项传递给 Mercurial 命令,否则它将不可见,并且默认情况下不会推送到远程存储库。不过我认为如果你真的愿意的话你可以强迫它。

如果您要修剪的 cset 具有您想要保留的祖先,那么您必须运行 hg escape 来重新设置这些变更集的基础。 hg evolve 会自动执行此操作。否则,您无需执行任何操作。

This is a use case for the Evolve extension. It's currently not bundled with Mercurial, so it is technically a third party extension. But it's being used quite heavily by a bunch of people, including Mercurial developers, is being very actively developed, and isn't going anywhere.

With the Evolve extension, you simply do

hg prune -r revname

and get on with your life. The cset will still be there, but obsoleted. It won't be visible unless you pass the --hidden option to Mercurial commands, and by default won't be pushed to remote repositories. Though I think you can force it if you really want to.

If the cset you are pruning has ancestors you want to keep, then you'll have to run hg evolve to rebase those changesets. hg evolve will do so automatically. Otherwise, you don't have to do anything.

第几種人 2024-09-26 02:03:15

您可以将损坏的存储库克隆到新的存储库,而无需克隆不需要的头。然后删除旧的存储库,将新创建的克隆移动到原始位置并继续使用它。这将需要一些时间,但您将获得一个完全干净的存储库,没有任何不需要的修订的迹象。

hg clone --rev myGoodResition myDirtyRepo myCleanRepo

You may clone your corrupted repo to a new one without cloning that unwanted head. Then remove old repository, move newly created clone to the original place and continue working with it. This will take some time, but you'll get a perfectly clean repository without a sign of that unwanted revision.

hg clone --rev myGoodResition myDirtyRepo myCleanRepo
糖粟与秋泊 2024-09-26 02:03:15

当我想要斩首错误创建的头时,我多次遇到这个问题。我总是希望看到它从地球表面消失。

在本地副本上,获取最新版本,然后:

  1. 找到要剥离的磁头的开头(新颈部开始分支的位置),获取修订号

  2. 剥离它。


资料来源:提示和技巧

资料来源:PruningDeadBranches#Using_strip

hg --config extensions.hgext.mq= strip -n <rev>
  1. 进行简单的文件更新(向文件添加空格)、提交并推送。

您的存储库现在应该已剥离头部。最后一步很重要,因为剥离不会创建任何可以推送到中央存储库的更改。如果没有最后一步,您只能局部剥离头部。

I have run into this issue many times when I want to behead a head that was created in error. I always want to see it disappear off the face of the Earth.

On your local copy, get the latest and then:

  1. Find the beginning of a head you want to strip (where a new neck starts to branch off), get the revision number

  2. Strip it.


Source: TipsAndTricks.

Source: PruningDeadBranches#Using_strip.

hg --config extensions.hgext.mq= strip -n <rev>
  1. Make a trivial file update (add a whitespace to a file), commit and push.

Your repo should now have the head stripped. The last step is important as stripping doesn't create any changes you can push to your central repository. Without the last step you only have stripped the head locally.

情深缘浅 2024-09-26 02:03:14

使用您想要忘记的修订将存储库更新到头部,然后使用 hg commit --close-branch 将该(匿名)分支标记为关闭。然后更新到您想要的分支的头部,并继续工作。

如果您对 hg Heads 使用 -c 选项,您仍然可以看到关闭的分支,但默认情况下它不会显示,并且 hg merge > 将知道不要尝试与封闭的头部合并。

第一次将这个封闭的头推送到另一个存储库时,您将需要使用 hg push --force ,因为当您推送时,您实际上是在远程存储库中创建了其他头。因此,请告诉 Mercurial,使用 --force 就可以了。拉紧头部的人不会受到任何警告的困扰。

Update your repository to the head with the revision that you want to forget about, then use hg commit --close-branch to mark that (anonymous) branch as closed. Then update to the head of the branch that you do want, and continue working.

You can still see the closed branch if you use the -c option to hg heads, but it won't show up by default and hg merge will know not try to merge with the closed head.

You will need to use hg push --force the first time you push this closed head to another repository since you are actually create additional heads in the remote repository when you push. So tell Mercurial that this is okay with --force. People who pull the closed head wont be bothered by any warnings.

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