使用PowerShell和SVN删除未版本化的文件

3
我正在尝试使用PowerShell编写构建脚本来检出代码。我需要能够用SVN仓库中的相应更改替换工作副本中所做的任何修改。这还包括删除在仓库中已删除但未在工作副本中删除的任何文件。
不幸的是,我无法进行全新检出,因为每次运行构建脚本时检出所有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

我似乎无法将第三行的输出存储到 $x 中,而且我不确定其余部分是否正确。

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

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

4个回答

6
如果你想从工作目录中删除未跟踪和忽略的文件,请尝试以下操作:
svn st --no-ignore | %{ if($_ -match '^[?I]\s+(.+)'){ $matches[1]} } | rm -whatif

确认命令符合要求后,删除-whatif选项。


0

我使用了以下内容:

&$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

0
svn revert -R $releaseDirectory

0

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

请参考 源代码

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接