Mercurial 恢复/取消单个文件

发布于 2024-09-30 13:18:20 字数 152 浏览 6 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

追风人 2024-10-07 13:18:20

从 TortoiseHg 2.8.1 开始,

  1. 出现问题时提交
  2. 右键单击​​要回滚到的修订版,选择“浏览修订版”
  3. 找到要恢复到此修订版的文件,右键单击“恢复到此修订版”( Ctrl+Shift+R
  4. 对要恢复的所有文件重复 3

As of TortoiseHg 2.8.1

  1. Commit in case something goes wrong
  2. Right click the revision you want to roll back to, select Browse At Revision
  3. Find the file you want to revert to this revision, right click, 'Revert to this revision (Ctrl+Shift+R)
  4. Repeat 3 for all files you want to revert
溺ぐ爱和你が 2024-10-07 13:18:20

由于 TortoiseHG 的风格(~)变化,Raghuram 的答案不再正确。 “存储库浏览器”已重命名为“TortoiseHG Workbench”,但更重要的是,“恢复文件内容”不再是对上下文菜单。

从版本 2.0.4 开始,您需要:

  1. 提交当前存储库,以防出现问题。
  2. 在“TortoiseHG Explorer”中打开相关变更集
  3. 在文件列表中,右键单击要恢复的文件。
  4. 从上下文菜单中选择“恢复到修订版本”。
  5. 您将看到一个确认对话框,其中包含一个标记为“将所有文件恢复为此版本”的复选框。确保它未被选中。
  6. 点击“确定”。
  7. 验证是否仅恢复了该文件。如果所有内容都已还原,请更新到步骤 1 中创建的修订版。

我第一次尝试此操作时,我不确定我做错了什么,但我还原了整个存储库而不是单个文件。因此,在尝试之前一定要确保提交新的修订版。

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:

  1. Commit your current repository in case something goes wrong.
  2. Open the relevant changeset in "TortoiseHG Explorer"
  3. In the file listing, right-click on the file you which to revert.
  4. Select "Revert to Revision" from the context menu.
  5. You'll be presented with a confirmation dialog that contains a checkbox labeled "Revert all files to this revision". Make sure that it's unchecked.
  6. Hit "OK".
  7. Verify that only that file was reverted. If everything was reverted, update to the revision created in step 1.

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.

恬淡成诗 2024-10-07 13:18:20

打开存储库浏览器,转到感兴趣的变更集。您将看到已更改文件的列表。选择您感兴趣的文件,然后单击恢复文件内容

Open Repository Browser, go to the interested changeset. You will see a list of changed files. Choose the file you are intersted and Click on Revert file contents

夜空下最亮的亮点 2024-10-07 13:18:20

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

墨洒年华 2024-10-07 13:18:20

我至少找到了第二部分的答案。要查看旧版本的单个文件的内容,请在 TortoiseHg 中执行以下操作:

  1. 右键单击​​该文件并选择存储库资源管理器。
  2. 单击您想要恢复到的修订版本。
  3. 右键单击左下窗格中的文件。选择修订时查看或修订时保存。

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:

  1. Right click on the file and select repository explorer.
  2. Click on the revision you'd like to revert back to.
  3. Right click on the file in the bottom left pane. Select either view at revision or save at revison.
陌路终见情 2024-10-07 13:18:20

要使用 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..."

淡写薰衣草的香 2024-10-07 13:18:20

虽然建议使用 TortoiseHg 的 Browse at rev... 将帮助您查看更改的内容(即您可能想要撤销的内容),但它不会帮助您撤销文件 - 如果,正如多个答案所暗示的那样,您选择恢复到修订版,您将只会撤销后续更改,而不是更改集中的更改。

撤消单个文件的更改集的最简单方法(至少从 TortoiseHg 2.6.1 开始):

  1. 在 Windows 资源管理器中浏览到该文件,然后选择它
  2. 右键单击,然后从 TortoiseHg 上下文子菜单中选择修订版历史记录
  3. 选择您要取消的版本之前的修订版,
  4. 单击鼠标右键,然后选择恢复到修订版
  5. 确保“将所有文件恢复到”此修订版”复选框未选中(它将
    遵循这些步骤后默认为)

当然,如果“旧变更集”是指您想要保留对该文件的后续更改,则除了检查变更集并手动撤消更改之外,没有其他方法可以做到这一点。

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 choose Revert 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):

  1. Browse to the file in Windows explorer, and select it
  2. Right-click, and from the TortoiseHg context submenu, choose Revision History
  3. Select the revision prior to the one you're trying to back out
  4. Right-click, and choose Revert to Revision
  5. Make sure the "Revert all files to this revision" checkbox is unchecked (it will
    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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文