Mercurial:如何撤消更改?
使用 Mercurial 时,如何撤消自上次提交以来工作目录中的所有更改?这似乎是一件简单的事情,但我却忽略了它。
例如,假设我有 4 次提交。然后,我对我的代码进行一些更改。然后我认为我的更改很糟糕,我只想回到上次提交时的代码状态。所以,我想我应该这样做:
hg update 4
4 是我最新提交的修订号。但是,Mercurial 不会更改我的工作目录中的任何文件。为什么不呢?
When using Mercurial, how do you undo all changes in the working directory since the last commit? It seems like this would be a simple thing, but it's escaping me.
For example, let's say I have 4 commits. 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. But, Mercurial doesn't change any of the files in my working directory. Why not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
hg revert
就可以了。它会将您恢复到上次提交。
--all
将恢复所有文件。请参阅其手册页描述的链接。
hg update
通常用于在从不同的存储库或交换分支拉取后刷新工作目录。hg up myawesomebranch
。它还可用于恢复到特定版本。hg up -r 12
。hg revert
will do the trick.It will revert you to the last commit.
--all
will revert all files.See the link for the Man Page description of it.
hg update
is usually used to refresh your working directory after you pull from a different repo or swap branches.hg up myawesomebranch
. It also can be used to revert to a specific version.hg up -r 12
.hg revert
的替代解决方案是hg update -C
。您可以使用此单个命令放弃本地更改并更新到某些修订版。我通常更喜欢输入
hg up -C
因为它比hg revert --all --no-backup
短:)An alternative solution to
hg revert
ishg 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 thanhg revert --all --no-backup
:)hg revert
是您的朋友:hg update
将您对当前工作副本的更改与目标修订版合并。将最新版本与更改的文件(=当前工作副本)合并会导致与您已有的更改相同,即,它什么都不做:-)如果您想阅读 Mercurial,我会推荐非常精彩的教程 < a href="http://hginit.com/" rel="noreferrer">汞初始化。
hg revert
is your friend:hg update
merges your changes to your current working copy with the target revision. Merging the latest revision with your changed files (=current working copy) results in the same changes that you already have, i.e., it does nothing :-)If you want to read up on Mercurial, I'd recommend the very awesome tutorial Hg Init.
然后
为我工作
and then
works for me