【问题标题】:Revert all files with a specified name还原具有指定名称的所有文件
【发布时间】:2017-06-15 17:53:02
【问题描述】:

您好,我想恢复对本地存储库中具有特定文件名的文件的所有更改。 在这种情况下AssemblyInfo.vb,我使用的是TortoiseSVN cli。

我有以下目录结构

    • 项目 1
      • 文件1.txt
      • 我的项目
        • AssemblyInfo.vb
    • 项目 2
      • 文件2.txt
      • 我的项目
        • AssemblyInfo.vb

现在站在Root 中,我运行命令svn.exe revert --recursive AssemblyInfo.vb,我得到的输出是:

Skipped 'AssemblyInfo.vb'

我尝试在文件名之前添加双精度和单精度 *,但没有成功,--recursive/-R 工作还是我缺少什么?

svn help revert 给出以下输出:

revert: Restore pristine working copy state (undo local changes).
usage: revert PATH...

  Revert changes in the working copy at or within PATH, and remove
  conflict markers as well, if any.

  This subcommand does not revert already committed changes.
  For information about undoing already committed changes, search
  the output of 'svn help merge' for 'undo'.

Valid options:
  --targets ARG            : pass contents of file ARG as additional args
  -R [--recursive]         : descend recursively, same as --depth=infinity
  --depth ARG              : limit operation by depth ARG ('empty', 'files',
                             'immediates', or 'infinity')
  -q [--quiet]             : print nothing, or only summary information
  --changelist [--cl] ARG  : operate only on members of changelist ARG

Global options:
  --username ARG           : specify a username ARG
  --password ARG           : specify a password ARG (caution: on many operating
                             systems, other users will be able to see this)
  --no-auth-cache          : do not cache authentication tokens
  --non-interactive        : do no interactive prompting (default is to prompt
                             only if standard input is a terminal device)
  --force-interactive      : do interactive prompting even if standard input
                             is not a terminal device
  --trust-server-cert      : deprecated; same as
                             --trust-server-cert-failures=unknown-ca
  --trust-server-cert-failures ARG : with --non-interactive, accept SSL server
                             certificates with failures; ARG is comma-separated
                             list of 'unknown-ca' (Unknown Authority),
                             'cn-mismatch' (Hostname mismatch), 'expired'
                             (Expired certificate), 'not-yet-valid' (Not yet
                             valid certificate) and 'other' (all other not
                             separately classified certificate errors).
  --config-dir ARG         : read user configuration files from directory ARG
  --config-option ARG      : set user configuration option in the format:
                                 FILE:SECTION:OPTION=[VALUE]
                             For example:
                                 servers:global:http-library=serf

如果我在直接包含修改后的AssemblyInfo.vb 的目录中运行svn.exe revert --recursive AssemblyInfo.vb,它会按预期工作。

【问题讨论】:

    标签: windows svn tortoisesvn command-line-interface revert


    【解决方案1】:

    在 Linux 上,这可以使用来自 findutilsfindxargs 命令的组合来完成:

    find -name AssemblyInfo.vb | xargs svn revert
    

    在 Windows 上,您可能可以安装和使用包含这些实用程序的 Cygwin

    【讨论】:

    • 虽然安装 Cygwin 来解决这个问题似乎有点过头了,但最大的问题是为什么 --recursive 不起作用,它打算如何使用?
    • --recursive 应该用于恢复目录。在您的情况下,您正在还原单个文件。对于这个特定的目录布局,您也可以svn.exe revert *\*\AssemblyInfo.vb。它将同时还原两个 AssemblyInfo.vb 文件。
    • 如果我在 Windows 上运行svn.exe revert *\*\AssemblyInfo.vb,我会得到svn: E155010: The node '...Root\*' was not found.
    【解决方案2】:

    svn revert 旨在帮助修复错误,而不是通过“帮助”用户意外或无意地删除其本地和未提交的更改而导致问题。

    如果您想恢复所有 SVN 工作副本或目录及其所有子目录中的更改,您可以运行svn revert . -R。但是,如果您的工作副本包含您不想丢失的有效未提交更改和您想要恢复为未修改状态的更改,则不得运行此命令。

    恢复本地更改是一个不可逆操作。因此,通过svn revert 还原SVN 工作副本中的本地更改必须谨慎。假设您正在处理一项任务,并且尚未提交一些您已经进行了几个小时的重要更改。但与此同时,您在要还原的文件或目录中进行了一些更改。在工作副本的根目录下不小心运行svn revert . -R 将恢复所有工作副本中未提交的更改。

    引用SVNBook | svn revert

    svn revert 本质上是 dangerous,因为它的全部目的是 丢弃数据——即您未提交的更改。一旦你已经 还原,Subversion 没有办法取回那些未提交的 变化。

    如果您没有向svn revert 提供目标,它将什么也不做。到 防止您意外丢失工作副本中的更改,svn revert 要求您明确提供至少一个目标。


    现在,当我站在 Root 中时,我运行命令 svn.exe revert --recursive AssemblyInfo.vb 我得到的输出是:

    svn revert 不能以这种方式工作。默认情况下,它使用--depth=empty 运行,以确保它不会恢复到超出用户预期的程度。但是使用-R 运行svn revert 与使用--depth=infinity 运行它是一样的。一般来说,在这种特殊情况下,--recursive--depth=infinity 的别名,其目的是帮助用户恢复所有本地修改(例如无效合并后)。

    当您使用--recursive 运行svn revert 时,该工具希望您指定工作副本中目录的路径,并且该操作将恢复所有此目录中的更改,并且它的孩子。 如果命令的目标是文件,则没有效果。

    您要查找的是--targets 和一些脚本。例如,在 PowerShell 控制台中运行以下命令(我确信它可以在 PowerShell 中比在此示例中更优雅地完成):

    (dir -Path "files.html" -Recurse -File).FullName | Out-File -Encoding ASCII mytargets.txt
    svn revert --targets mytargets.txt
    

    dir 是 PowerShell 中 Get-ChildItem cmdlet 的别名。在这种情况下,它会获取名称为files.html 的所有文件的列表,并将完整路径写入mytargets.txt 文件。然后它运行svn revertmytargets.txt 读取路径并恢复对文件所做的本地修改。

    我建议使用这种方法,而不是将输出通过管道传输到 svn revert,因为您可以(并且应该)查看 svn revert 将处理的项目列表。这可以帮助您确保您不会还原更多您实际想要的。

    【讨论】:

      猜你喜欢
      • 2018-03-20
      • 2013-04-19
      • 2014-04-26
      • 2012-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-29
      • 2020-12-17
      相关资源
      最近更新 更多