Mercurial 恢复/取消单个文件
在 Mercurial 中,我有一个旧的变更集,除了对单个文件的更改之外,它都很好。我如何恢复对该单个文件的更改?
即使只是能够查看上一个变更集的文件状态也会很好,然后我就可以剪切和删除文件。粘贴。
我的 Mercurial 客户端是 TortoiseHg。
In Mercurial I have an old changeset which is all good apart from the alterations to a single file. How would I revert the alterations to that single file?
Even just being able to view the state of the file at the previous changeset would be good then I could cut & paste.
My Mercurial client is TortoiseHg.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
从 TortoiseHg 2.8.1 开始,
As of TortoiseHg 2.8.1
由于 TortoiseHG 的风格(~)变化,Raghuram 的答案不再正确。 “存储库浏览器”已重命名为“TortoiseHG Workbench”,但更重要的是,“恢复文件内容”不再是对上下文菜单。
从版本 2.0.4 开始,您需要:
我第一次尝试此操作时,我不确定我做错了什么,但我还原了整个存储库而不是单个文件。因此,在尝试之前一定要确保提交新的修订版。
Raghuram's answer is no longer correct due to stylistic(~) changes to TortoiseHG. "Repository Browser" has been renamed "TortoiseHG Workbench", but, more importantly, "Revert file contents" is no longer an action on the context menu.
As of version 2.0.4, you'll want to:
The first time I tried this, I'm not sure what I did wrong, but I reverted the whole repository instead of the single file. So, definitely make sure you commit a new revision before trying it.
打开
存储库浏览器
,转到感兴趣的变更集。您将看到已更改文件的列表。选择您感兴趣的文件,然后单击恢复文件内容
Open
Repository Browser
, go to the interested changeset. You will see a list of changed files. Choose the file you are intersted and Click onRevert file contents
CLI 版本,适用于 TortoiseHG 的任何(新)版本
为了仅撤消变更集 CSET 中引入的 FILE 中的更改,请使用这种形式的退出
hg backout -r CSET --include FILE
CLI-version, applicable to any (fresh) version of TortoiseHG
In order to undo changes only in FILE, introduced in changeset CSET, use this form of backout
hg backout -r CSET --include FILE
我至少找到了第二部分的答案。要查看旧版本的单个文件的内容,请在 TortoiseHg 中执行以下操作:
I've discovered the answer to the second part at least. To view the contents of a single file at an old revision do the following in TortoiseHg:
要使用 TortoiseHg 查看旧版本的文件(自版本 2.2.1 起),请打开 TortoiseHG Workbench,右键单击旧版本,然后单击“浏览版本...”
To view an old version of a file using TortoiseHg (as of version 2.2.1), open TortoiseHG Workbench, right click on an old rev, and click "Browse at rev..."
虽然建议使用 TortoiseHg 的
Browse at rev...
将帮助您查看更改的内容(即您可能想要撤销的内容),但它不会帮助您撤销文件 - 如果,正如多个答案所暗示的那样,您选择恢复到修订版
,您将只会撤销后续更改,而不是更改集中的更改。撤消单个文件的更改集的最简单方法(至少从 TortoiseHg 2.6.1 开始):
恢复到修订版
遵循这些步骤后默认为)
当然,如果“旧变更集”是指您想要保留对该文件的后续更改,则除了检查变更集并手动撤消更改之外,没有其他方法可以做到这一点。
While the recommendation to use TortoiseHg's
Browse at rev...
will help you see what got changed (i.e. what you might want to back out), it won't help you back out the file--if, as more than one answer suggests, you chooseRevert to Revision
, you will only be backing out subsequent changes, not the change in the changeset.The easiest way to undo a changeset for a single file (at least, as of TortoiseHg 2.6.1):
Revision History
Revert to Revision
be by default after following these steps)
Of course, if by "old changeset" you mean there are subsequent changes to that file that you want to keep, there is no way to do that except to examine the changeset and manually undo the changes.