删除所有本地变更集并恢复为树
我正在使用 Mercurial,但我在本地陷入了严重的混乱,有三个头。我无法推送,我只想删除所有本地更改和提交,并以完全干净的代码和干净的历史记录重新开始。
换句话说,我希望最终得到(a)本地与远程分支尖端中存在的代码完全相同的代码,以及(b)没有任何本地提交的历史记录。
我知道 hg update -C
会覆盖任何本地更改。但是如何删除本地提交呢?
需要明确的是,我没有兴趣保留我在本地所做的任何工作。我只想要最简单的方法来恢复到完全干净的本地结帐。
I'm using Mercurial and I've got into a terrible mess locally, with three heads. I can't push, and I just want to delete all my local changes and commits and start again with totally clean code and a clean history.
In other words, I want to end up with (a) exactly the same code locally as exists in the tip of the remote branch and (b) no history of any local commits.
I know hg update -C
overwrites any local changes. But how do I delete any local commits?
To be clear, I have no interest in preserving any of the work I've done locally. I just want the simplest way to revert back to a totally clean local checkout.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
当最简单的方法(新的
hg 克隆
)不切实际时,我会使用hg strip
:重复,直到
hg Outgoing
保持安静。请注意,hg strip $rev
删除了$rev
及其所有后代。请注意,您可能必须首先在 Mercurial 设置中启用
strip
。PS:一种更聪明的方法是使用 revset 语言,并执行以下操作:
When the simplest way (a new
hg clone
) isn't practical, I usehg strip
:Repeat until
hg outgoing
stays quiet. Note thathg strip $rev
obliterates$rev
and all its descendants.Note that you may have to first enable
strip
in your Mercurial settings.PS: an even smarter approach is to use the revset language, and do:
您需要创建一个本地克隆,仅保留远程存储库中也存在的变更集。使用 TortoiseHg、
hg log
或类似工具来确定您的哪个版本是您的最新版本没有做(混乱开始之前的那个)。使用 hg outgoing 可以在这里提供帮助 - 它将列出您所做的所有更改集 - 选择早于其中任何一个的修订号。如果目标修订版名为
good
并且您的克隆名为foo
,则执行以下操作:这将是一个快速的本地操作 - 没有理由下载一切又来了。
foo-clean
克隆将仅包含修订版good
之前的变更集。您现在可以将 foo-clean/.hg/hgrc 替换为 foo/.hg/hgrc ,以保留存储库本地设置,例如默认推/拉路径。当您对
foo-clean
拥有foo
所需的一切感到满意时,只需删除foo
并重命名foo-clean 到
foo
。执行hg pull
将任何新的变更集从远程存储库获取到您的克隆中,然后像平常一样继续。如果没有人将新的变更集推送到远程存储库,那么确定要使用哪个版本作为上面的
good
非常简单:hg id default
会告诉您 ID远程存储库中的提示。You'll want to make a local clone where you preserve only the changesets that are also present in the remote repository. Use TortoiseHg,
hg log
or similar to figure out which of your revisions is that lastest revision you didn't make (the one before the mess started). Usinghg outgoing
can help here -- it will list all the changesets you made -- pick a revision number earlier than any of those.If the target revision is called
good
and your clone is calledfoo
, then do:This will be a fast, local operation -- there is no reason to download everything again. The
foo-clean
clone will only contain changesets up to revisiongood
. You can now replacefoo-clean/.hg/hgrc
withfoo/.hg/hgrc
in order to preserve your repository-local settings such as the default push/pull path.When you are satisfied that
foo-clean
has everything you need fromfoo
, then simply deletefoo
and renamefoo-clean
tofoo
. Do ahg pull
to get any new changesets from the remote repository into your clone and continue like normal.If nobody has pushed new changesets to the remote repository, then it is very simple to determine which revision you want to use as
good
above:hg id default
will tell you the ID of the tip in the remote repository.好的。因此,只需删除所有本地内容,
hg init
新的本地存储库和hg pull
您拥有的最新提示即可。在此之后不要忘记hg update
。Ok. So just delete all the local stuff,
hg init
the new local repository andhg pull
the latest tip you have. Don't forget tohg update
after this.您可以使用
以杀死本地存储库中的任何修订及其子树。
https://www.mercurial-scm.org/wiki/Strip
但是不要'不要尝试将其用于已经推送的任何内容。
You may use
to kill any revision and its subtree in your local repository.
https://www.mercurial-scm.org/wiki/Strip
But don't try to use it for anything that has been already pushed.
只需删除本地系统上的所有内容并重新克隆远程存储库即可。
Just delete everything you have on your local system and re-clone the remote repo.
对我有用。
它会删除所有未推送到使用您的作者姓名创建的默认存储库的修订。
您还可以使用此样式使其不检查默认存储库,而是检查另一个存储库
does the trick for me.
It strips all revisions that aren't pushed to the default repository which are created with your author name.
You can also use this style to make it not checking with the default repository but with another Repository
如果您使用 TortoiseHg,摆脱(小)混乱的一个简单方法是首先更新到最新版本,然后选择您的变更集并启动“与本地合并”。当合并对话框出现时,只需单击小“+”图标即可显示一些额外选项,其中之一是“放弃合并目标(其他)修订版中的变更集”。这样做意味着您的变更集仍将位于存储库中并被推送,但不会产生任何效果,因为它们将在合并中被丢弃。如果您有大量跨越多个头的变更集,您可能不想以这种方式污染存储库,但这是一个简单的修复,并且如果您要丢弃的变更集包含您以后可能想要引用的数据,则值得考虑。
If you are using TortoiseHg, one simple way to get out of a (small) mess is to first update to the latest revision, then select your changesets and initiate "merge with local". When the merge dialogue appears, simply click the little '+' icon to reveal some extra options, one of which is "discard changesets from merge target (other) revision". Doing this will mean your changesets will still be in the repo and get pushed, but will have no effect, because they will be discarded in the merge. If you have a lot of changesets spanning many heads, you might not want to pollute the repo this way, but it's a simple fix and worth considering if the changesets you are discarding contain data that you may later want to reference.