我是一名 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?
发布评论
评论(5)
如果您还没有提交,并且听起来您还没有提交,则可以使用
hg update --clean
撤消所有合并工作。然而,在较新的 Mercurial 中,有一个方便的命令可以重新合并单个文件:
hg resolve path/to/file.ext
。来自hg帮助解决
: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 thehg help resolve
:这很接近:
hg update --clean
This is close:
hg update --clean
从 git,命令:
等于
From git, commands:
are equal to
Hg 手册的 GitConcepts 页面解释了如何执行许多操作
git
用户熟悉 Mercurial。Mercurial 没有任何内置的 git reset --hard 行为。但是,
strip
扩展提供了一个strip
命令。要使用,首先在您的strip
code>~/.hgrc file::注意:此扩展在 Mercurial 2.8 中以新版本提供。之前的版本在
mq< 中提供了
strip
命令/code> 扩展名。
现在您可以运行
hg strip
甚至hg help strip
等命令。要删除变更集及其所有子变更集,只需将该变更集指定为hg strip
的参数即可。例如,要删除您刚刚进行的最后一次提交(在您使用导致hg rollback
报告不再有任何事务需要回滚的命令之后),您可以删除tip
代码>修订版。每次运行此命令时,都会删除另一个修订版本。hg strip
的操作应被视为不可逆转;不熟悉的用户应在使用前备份其存储库。例如,使用 revsets 语法< /a>,我表示我想删除我的任何提交,这些提交会导致在运行
hg faces
时显示额外的头。如果您在下面的表达式中指定除tip
之外的特定修订版,则当前分支中不是所选修订版祖先的所有内容都将被修剪。当我发出命令 git reset --hard HEAD 时,这似乎最接近我想要的行为。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, thestrip
extension provides astrip
command which does. To use, first enablestrip
in your~/.hgrc
file::Note: this extension is shipped in new in Mercurial 2.8. Prior versions provided the
strip
command in themq
extension.Now you can run commands like
hg strip
or evenhg help strip
. To remove a changeset and all of its children, simply specify that changeset as an argument tohg strip
. For example, to remove the last commit you just made (after you used commands which causedhg rollback
to report that there is no longer any transaction to rollback), you can remove thetip
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.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 thantip
, 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 commandgit reset --hard HEAD
.我期望在 Mercurial 中找到 git reset --hard 的替代方案是:
然后,如果您也需要:
What I expected to find as an alternative to
git reset --hard
in mercurial was:And then if you need too: