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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2672454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:16:54  来源:igfitidea点击:

How do I git reset --hard HEAD on Mercurial?

gitmercurialmergedvcs

提问by Helder S Ribeiro

I'm a Git user trying to use Mercurial.

我是一个尝试使用 Mercurial 的 Git 用户。

Here's what happened: I did a hg backouton 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 HEADto wipe it out but, from what I've read, the index doesn't exist on Mercurial. So how do I back out from this?

这是发生的事情:我hg backout在一个我想恢复的变更集上做了一个。这创造了一个新的头,所以 hg 指示我合并(回到“默认”,我假设)。合并后,它告诉我我仍然必须提交。然后我注意到在解决合并中的冲突时我做错了,并决定我想要像之前一样拥有一切hg backout,也就是说,我希望这个未提交的合并消失。在 Git 上,这个未提交的东西会在索引中,我只是想把git reset --hard HEAD它抹掉,但是,从我读过的内容来看,Mercurial 上不存在该索引。那么我该如何退出呢?

回答by Ry4an Brase

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

如果您尚未提交,并且听起来您还没有提交,则可以使用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:

但是,在较新的 mercurial 中,有一个方便的命令可以重新合并单个文件:hg resolve path/to/file.ext. 来自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)

The available actions are: ...

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

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

回答by sblom

This is close:

这很接近:

hg update --clean

hg update --clean

回答by binki

The Hg Manual's GitConceptspage explains how to do many actions gitusers are familiar with in Mercurial.

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

Mercurial doesn't have any built-in git reset --hardbehavior. However, the stripextension provides a stripcommand which does. To use, first enable stripin your ~/.hgrcfile::

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

[extensions]
strip =

Note: this extension is shipped in new in Mercurial 2.8. Prior versions provided the stripcommand in the mqextension.

注意:这个扩展是在 Mercurial 2.8 中新增的。之前的版本stripmq扩展中提供了该命令。

Now you can run commands like hg stripor 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 rollbackto report that there is no longer any transaction to rollback), you can remove the tiprevision. 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甚至hg help strip. 要删除变更集及其所有子项,只需将该变更集指定为 的参数即可hg strip。例如,要删除您刚刚进行的最后一次提交(在您使用导致hg rollback报告不再有任何事务要回滚的命令之后),您可以删除tip修订。每次运行此命令时,都会删除另一个修订版。hg strip的行为应该被认为是不可逆转的;不熟悉的用户应该在使用前备份他们的存储库。

$ 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.

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

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

回答by Dariusz Filipiak

From git, commands:

从 git,命令:

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