我有一个Subversion存储库的工作副本,有没有办法用一个命令或工具删除该工作副本中的所有未版本或被忽略的文件? 需要一个最佳解决方案,应该删除列表视图和树视图中的所有未版本控制的文件夹和文件
我使用了以下代码
ProcessStartInfo psi = new ProcessStartInfo("svn.exe", "status --non-interactive");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.WorkingDirectory = directory;
using (Process process = Process.Start(psi))
{
string line = process.StandardOutput.ReadLine();
while (line != null)
{
if (line.Length > 7)
{
if (line[0] == '?')
{
string relativePath = line.Substring(8);
Console.WriteLine(relativePath);
string path = Path.Combine(directory, relativePath);
if (Directory.Exists(path))
{
DeleteDir(path);
}
else if (File.Exists(path))
{
FileInfo file = new FileInfo(path);
file.IsReadOnly = false;
File.Delete(path);
}
}
}
line = process.StandardOutput.ReadLine();
}
}
}
static void DeleteDir(string root)
{
DirectoryInfo di = new DirectoryInfo(root);
FileInfo[] fis = di.GetFiles();
foreach (FileInfo fi in fis)
{
fi.IsReadOnly = false;
File.Delete(fi.FullName);
}
foreach (DirectoryInfo dinfo in di.GetDirectories())
{
DeleteDir(dinfo.FullName);
}
if (di.GetDirectories().Length == 0) { Directory.Delete(di.FullName); return; }
}
答案 0 :(得分:0)
也许你可以使用TortoiseSVN来使用这个过程:
答案 1 :(得分:-1)
svn status | grep ^\? | sed -e 's/^.......\(.*\)$/\1/g' | sed -e 's/\\/\//g' | xargs -Ifile rm -rf file
参考:https://artofsoftware.org/2012/03/30/svn-command-line-to-remove-unversioned-files/