如何在 Mercurial 中恢复 1 个或多个已提交的文件,而不是整个变更集
假设我有文件 File_A
、File_B
和 File_C
。我故意编辑了 File_A
和 File_B
,但 File_C
我只是添加了一些我不打算提交的调试代码。然后我不小心做了一个
hg commit -m "comment"
How do just revert/rollback/backout File_C
?基本上我很高兴能够继续,
hg update -r <oneRevBack> File_C
hg commit -m "put C back"
但更新不会使用过滤器 AFAIK,因此它也会恢复 File_A
和 File_B
。我可以将 File_C
复制到某个地方,hg update
,然后将其复制回来,但这似乎很蹩脚。有没有办法直接在 Mercurial 中执行此操作?
Say I have files File_A
, File_B
and File_C
. I edit File_A
and File_B
on purpose but File_C
I just added some debugging code that I don't plan to commit. Then by accident I do a
hg commit -m "comment"
How do just revert/rollback/backout File_C
? Basically I'd be happy to be able to go
hg update -r <oneRevBack> File_C
hg commit -m "put C back"
but update doesn't take a filter AFAIK so it's also going to revert File_A
and File_B
. I can copy File_C
somewhere, hg update
, then copy it back but that seems lame. Is there a way to do this directly in Mercurial?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您使用
hg revert
而不是hg update
,您想要使用的确切命令就会起作用The exact command you wanted to use would have worked if you used
hg revert
instead ofhg update
在大多数情况下,VonC 的解决方案都是完美的。但是,如果无法选择回滚(例如,因为有问题的提交不是最后一次,或者因为您执行了复杂的部分提交),那么您可以使用对
File_C< 的不需要的更改的反向差异进行新的提交/code>:
其中
REVISION
指的是File_C
意外提交的提交。第一个命令生成相关文件的反向差异。它的输出通过管道传输到hg import
(不要忘记尾随的-
)。更新:您还可以使用backout命令:
backout命令会更改您的工作副本,因为它会撤消在rev中提交的对
File_C
的更改。修订
。之后,显式提交恢复。In most cases VonC's solution is just perfect. However, if rollback is no option (e.g. because the commit in question is not the last one or because you did a complex partial commit), then you can do a new commit with the reversed diff of the unwanted changes to
File_C
:Where
REVISION
refers to the commit whereFile_C
has been committed accidentally. The first command produces the reversed diff for the file in question. It's output is piped tohg import
(don't forget the trailing-
).UPDATE: You can also use the backout command:
The backout command changes your working copy in that it undoes the changes to
File_C
commited in rev.REVISION
. Afterwards the revert is committed explicitly.您可以使用
hg rollback
撤消上次提交,然后再次重新执行,这次没有文件C
。(如 Mercurial 常见问题中所述,以及在此常见问题解答条目中指出“有回滚事务时没有备份”,所以谨慎使用)
You could use
hg rollback
to undo your last commit, and then re-do it again, this time without the fileC
.(as mentioned in Mercurial FAQ, and also in this FAQ entry where it is noted that "there is no backup when you rollback a transaction", so use it with caution)
你可以通过以下方式将其恢复到上次提交
you can revert it to last commit via
您还可以使用交互模式:
选择您想要还原的内容并确认。
You can also use interactive mode:
Select what you want reverted and confirm.