Mercurial:如何撤消上一次未推送的提交? [英] Mercurial: how to undo last unpushed commit?

查看:118
本文介绍了Mercurial:如何撤消上一次未推送的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意外地对本地存储库进行了提交.更具体地说,当我打算一次提交一个文件时,我一次提交了对许多文件的更改.

I have accidentally made a commit to my local repository. To be more specific, I committed changes to lots of files all at once, when I meant to commit them one at a time.

如何撤消此提交并使工作副本恢复到提交之前的状态,以便我可以首先完成本应做的事情?

How do I undo this commit and get my working copy back to the state it was before the commit so I can do what I should have done in the first place?

自提交以来,我还没有推动或拉动其他操作.

I have not pushed or pulled or anything else since the commit.

您可能会怀疑这是重复的,所以我将解释以下问题为何不同或不回答我的问题:

You may suspect this is a duplicate, so I will explain why the following questions are different, or do not answer my question:

Mercurial撤消上一次提交

对此问题的回答指出,您可以使用hg commit --amend进行此操作,但不解释操作方式或给出执行此操作的示例.硫脲的帮助对我也不是很清楚.

An answer to this one states that you can do this with hg commit --amend, but does not explain how or give an example of doing this. The mercurail help does not spell it out for me either.

如何回滚";最后一次对Mercurial提交?

使用hg rollback的状态.该命令显然已被弃用,无论如何我都尝试使用它,但是我得到了消息:没有可用的回滚信息.可惜这是行不通的,因为这将是实现我想要的东西的一种非常直观的方式.

States to use hg rollback. This command is apparently deprecated, I tried using it anyway, but I got the messge: no rollback information available. A shame this doesn't work as this would be a really intuitive way to achieve what I want.

推荐答案

基于 hg strip --keep --rev .
--keep: do not modify working directory during strip
--rev .(点表示最后一次提交.请阅读sid0关于后代的答案)

hg strip --keep --rev .
--keep: do not modify working directory during strip
--rev . (the dot denotes the last commit. read sid0's answer regarding descendants)

对于更熟悉git语言的人们,您正在寻找git reset --mixed HEAD^

For people more familiar with git language, you are looking for git reset --mixed HEAD^

hard会放弃您的更改,使您的工作消失"(我认为这不是一个选择)

hard which would discard your changes, making your work "disappear" (I assume that is not an option)

soft会撤消提交,但保留先前提交的文件的索引(即被跟踪)

soft would undo the commit, but keep previously committed files indexed (that is, tracked)

mixed将更改的文件保留在原位,但是告诉索引撤消提交.用git-speak表示:git st会说Changes not staged for commit

mixed keeps your changed files in place, but tells the index to undo the commit. in git-speak: git st would say Changes not staged for commit

另请参见 git-reset文档 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆