繁体   English   中英

使用powershell和svn删除未版本控制的文件

[英]Using powershell and svn to delete unversioned files

我正在尝试编写一个构建脚本来使用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 st --no-ignore | %{ if($_ -match '^[?I]\s+(.+)'){ $matches[1]} } | rm -whatif

一旦确认它正在执行您想要的操作,请删除-whatif

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

请参考来源

我使用了以下内容:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM