【问题标题】:Using powershell and svn to delete unversioned files使用 powershell 和 svn 删除未版本控制的文件
【发布时间】:2012-02-23 08:36:48
【问题描述】:

我正在尝试使用 Powershell 编写构建脚本来检查代码。我需要能够用 SVN 存储库中的适当更改替换对工作副本所做的任何修改。这还包括删除在 repo 中已删除但在工作副本中未删除的所有文件。

不幸的是,我无法进行干净的检查,因为每次运行构建脚本时检查所有 10GB 的代码效率很低。我该怎么做?

我一直在尝试这些方面的东西:

&$SVN_EXE revert $workingPath
&$SVN_EXE update $workingPath
$x = &$SVN_EXE status $localPath --no-ignore |  where {$_ -match "^[\?I]"} | %{$_ -replace "^[\?I]",""} # get the status, get any items with a ? and strip them out
$x | %{$_ -replace "[`n]",", "} # Replace newlines with commas
Remove-Item $x # Remove all the unversioned items

我似乎无法将第 3 行的输出存储到 $x 中,而且我不太确定其余部分是否可以这样做。

我不确定这是否是正确的方法,但如果是,我似乎无法存储和解析 SVN 状态的输出。

有人有什么建议吗?谢谢!

【问题讨论】:

    标签: svn version-control scripting powershell windows-scripting


    【解决方案1】:

    我使用了以下内容:

    &$SVN_EXE revert $workingPath
    &$SVN_EXE update $workingPath
    &$SVN_EXE status $localPath --no-ignore |
                    Select-String '^[?I]' |
                    ForEach-Object {
                        [Regex]::Match($_.Line, '^[^\s]*\s+(.*)$').Groups[1].Value
                    } |
                    Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
    

    【讨论】:

      【解决方案2】:

      如果您想从工作目录中删除未跟踪和忽略的文件,请尝试以下操作:

      svn st --no-ignore | %{ if($_ -match '^[?I]\s+(.+)'){ $matches[1]} } | rm -whatif
      

      一旦您确认-whatif 正在执行您希望它执行的操作,请删除它。

      【讨论】:

        【解决方案3】:

        cd $PATH

         svn status --no-ignore | Select-String '^[?I]' | ForEach-Object 
         {[Regex]::Match($_.Line, '^[^\s]*\s+(.*)$').Groups[1].Value} | Remove-Item - 
         Recurse -Force -ErrorAction SilentlyContinue
        

        请参考Source

        【讨论】:

          【解决方案4】:
          svn revert -R $releaseDirectory
          

          【讨论】:

            猜你喜欢
            • 2020-09-07
            • 1970-01-01
            • 2018-02-12
            • 1970-01-01
            • 2018-02-03
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多