[英]Mercurial: How do you undo changes?
When using Mercurial, how do you undo all changes in the working directory since the last commit? 使用Mercurial时,如何撤消自上次提交以来工作目录中的所有更改? It seems like this would be a simple thing, but it's escaping me.
这似乎是一件简单的事情,但它正在逃避我。
For example, let's say I have 4 commits. 例如,假设我有4次提交。 Then, I make some changes to my code.
然后,我对我的代码进行了一些更改。 Then I decide that my changes are bad and I just want to go back to the state of the code at my last commit.
然后我决定我的更改很糟糕,我只想回到上一次提交时的代码状态。 So, I think I should do:
所以,我想我应该这样做:
hg update 4
with 4 being the revision # of my latest commit. 4是我最新提交的修订版#。 But, Mercurial doesn't change any of the files in my working directory.
但是,Mercurial不会更改工作目录中的任何文件。 Why not?
为什么不?
hg revert
will do the trick. hg revert
将成功。
It will revert you to the last commit. 它会将您恢复到最后一次提交。
--all
will revert all files. --all
将还原所有文件。
See the link for the Man Page description of it. 请参阅Man Page描述的链接。
hg update
is usually used to refresh your working directory after you pull from a different repo or swap branches. 从不同的repo或swap分支拉出后,
hg update
通常用于刷新工作目录。 hg up myawesomebranch
. hg up myawesomebranch
。 It also can be used to revert to a specific version. 它还可用于恢复特定版本。
hg up -r 12
. hg up -r 12
。
An alternative solution to hg revert
is hg update -C
. hg revert
的另一种解决方案是hg update -C
。 You can discard your local changes and update to some revision using this single command. 您可以使用此单个命令放弃本地更改并更新到某些修订。
I usually prefer typing hg up -C
because it's shorter than hg revert --all --no-backup
:) 我通常喜欢输入
hg up -C
因为它比hg revert --all --no-backup
短hg revert --all --no-backup
:)
hg revert
is your friend: hg revert
是你的朋友:
hg revert --all
hg update
merges your changes to your current working copy with the target revision. hg update
将您对当前工作副本的更改与目标修订合并。 Merging the latest revision with your changed files (=current working copy) results in the same changes that you already have, ie, it does nothing :-) 将最新版本与已更改的文件(=当前工作副本)合并会导致您已经拥有的相同更改,即它不执行任何操作:-)
If you want to read up on Mercurial, I'd recommend the very awesome tutorial Hg Init . 如果你想阅读Mercurial,我会推荐非常棒的教程Hg Init 。
hg revert --all
and then 然后
hg pull -u
works for me 适合我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.