如何在 Mercurial 上 git reset --hard HEAD?

发布于 2024-08-29 07:59:13 字数 315 浏览 5 评论 0 原文

我是一名 Git 用户,正在尝试使用 Mercurial。

发生的事情是这样的:我对想要恢复的变更集执行了 hg backout。这创建了一个新头,因此 hg 指示我合并(我认为回到“默认”)。合并后,它告诉我我仍然必须提交。然后我注意到在解决合并中的冲突时我做错了一些事情,并决定我希望一切都像 hg backout 之前一样,也就是说,我希望这个未提交的合并消失。在 Git 上,这些未提交的内容将在索引中,我只需执行 git reset --hard HEAD 即可将其清除,但是,从我读到的内容来看,索引不存在于善变的。那么我该如何退出呢?

I'm a Git user trying to use Mercurial.

Here's what happened: I did a hg backout on a changeset I wanted to revert. That created a new head, so hg instructed me to merge (back to "default", I assume). After the merge, it told me I still had to commit. Then I noticed something I did wrong when resolving a conflict in the merge, and decided I wanted to have everything as before the hg backout, that is, I want this uncommited merge to go away. On Git this uncommited stuff would be in the index and I'd just do a git reset --hard HEAD to wipe it out but, from what I've read, the index doesn't exist on Mercurial. So how do I back out from this?

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

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

发布评论

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

评论(5

梦过后 2024-09-05 07:59:13

如果您还没有提交,并且听起来您还没有提交,则可以使用 hg update --clean 撤消所有合并工作。

然而,在较新的 Mercurial 中,有一个方便的命令可以重新合并单个文件:hg resolve path/to/file.ext。来自hg帮助解决

可用的操作有:...

 4) 放弃当前解决冲突的尝试,并且

重新启动
从头开始合并:“hg 解析文件...”(或“-a”表示所有
未解析的文件)

If you've not yet commited, and it sounds like you haven't you can undo all the merge work with hg update --clean.

However, in newer mercurial's there's a handy command to re-merge a single file: hg resolve path/to/file.ext. From the hg help resolve:

The available actions are: ...

 4) discard your current attempt(s) at resolving conflicts and

restart
the merge from scratch: "hg resolve file..." (or "-a" for all
unresolved files)

晚雾 2024-09-05 07:59:13

这很接近:

hg update --clean

This is close:

hg update --clean

脱离于你 2024-09-05 07:59:13

从 git,命令:

git reset --hard     # reset to last commit    
git clean -df        # delete untracked files

等于

hg update --clean    # reset to last commit  
hg purge             # delete untracked files

From git, commands:

git reset --hard     # reset to last commit    
git clean -df        # delete untracked files

are equal to

hg update --clean    # reset to last commit  
hg purge             # delete untracked files
丢了幸福的猪 2024-09-05 07:59:13

Hg 手册的 GitConcepts 页面解释了如何执行许多操作 git 用户熟悉 Mercurial。

Mercurial 没有任何内置的 git reset --hard 行为。但是,strip 扩展提供了一个 strip 命令。要使用,首先在您的 strip code>~/.hgrc file::

[extensions]
strip =

注意:此扩展在 Mercurial 2.8 中以新版本提供。之前的版本在 mq< 中提供了 strip 命令/code> 扩展名

现在您可以运行 hg strip 甚至 hg help strip 等命令。要删除变更集及其所有子变更集,只需将该变更集指定为 hg strip 的参数即可。例如,要删除您刚刚进行的最后一次提交(在您使用导致 hg rollback 报告不再有任何事务需要回滚的命令之后),您可以删除 tip代码>修订版。每次运行此命令时,都会删除另一个修订版本。 hg strip 的操作应被视为不可逆转;不熟悉的用户应在使用前备份其存储库。

$ hg strip tip

例如,使用 revsets 语法< /a>,我表示我想删除我的任何提交,这些提交会导致在运行 hg faces 时显示额外的头。如果您在下面的表达式中指定除 tip 之外的特定修订版,则当前分支中不是所选修订版祖先的所有内容都将被修剪。当我发出命令 git reset --hard HEAD 时,这似乎最接近我想要的行为。

$ hg strip "branch(tip) and not(ancestors(tip)::tip)"

The Hg Manual’s GitConcepts page explains how to do many actions git users are familiar with in Mercurial.

Mercurial doesn’t have any built-in git reset --hard behavior. However, the strip extension provides a strip command which does. To use, first enable strip in your ~/.hgrc file::

[extensions]
strip =

Note: this extension is shipped in new in Mercurial 2.8. Prior versions provided the strip command in the mq extension.

Now you can run commands like hg strip or even hg help strip. To remove a changeset and all of its children, simply specify that changeset as an argument to hg strip. For example, to remove the last commit you just made (after you used commands which caused hg rollback to report that there is no longer any transaction to rollback), you can remove the tip revision. Each time you run this command, another revision will be removed. hg strip’s actions should be considered irreversible; unfamiliar users should make backups of their repositories before using.

$ hg strip tip

For example, with revsets syntax, I indicate that I want to remove any commits of mine which result in extra heads being shown when I run hg heads. If you specify a particular revision in the below expression other than tip, everything in the current branch that is not an ancestor of your chosen revision will be trimmed. This seems closest to the behavior I want when I issue the command git reset --hard HEAD.

$ hg strip "branch(tip) and not(ancestors(tip)::tip)"
你又不是我 2024-09-05 07:59:13

我期望在 Mercurial 中找到 git reset --hard 的替代方案是:

hg strip --keep -r . # --keep optional
hg update --clean    # reset to last commit

然后,如果您也需要:

hg purge

What I expected to find as an alternative to git reset --hard in mercurial was:

hg strip --keep -r . # --keep optional
hg update --clean    # reset to last commit

And then if you need too:

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