如何安装 SVN CMD
如果你打开 TortoiseSVN xxx.exe
安装完后,就可以在 shell 或是 cmd 调用 svn 命令行了
如何还原文件
使用 svn help revert
查看该命令
实例:(Temporary).meta 文件没有修改,这时我们在 shell 输入:svn revert "H:\WorkFiles\ProjectArt\Assets\Art\(Temporary).meta"
,结果如下,没有什么反应
于是,我先修改一下该文件,保存一下,在来一次该命令,可以看到有:Reverted '(Temporary).meta'
的字样
如何C#调用 SVN还原指定文件
在 C# 中调用代码如下:
// jave.lin 2021/08/11
private void SVNRevertFileTest()
{
// TortoiseProc.exe /command:log /path:"H:\WorkFiles\ProjectArt\Assets\Art\(Temporary).meta" /closeonend:1
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo("svn");
info.Arguments = " revert \"H:\\WorkFiles\\ProjectArt\\Assets\\Art\\(Temporary).meta\"";
info.CreateNoWindow = false;
info.ErrorDialog = true;
info.UseShellExecute = true;
if (info.UseShellExecute)
{
info.RedirectStandardOutput = false;
info.RedirectStandardError = false;
info.RedirectStandardInput = false;
}
else
{
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.RedirectStandardInput = true;
info.StandardOutputEncoding = System.Text.UTF8Encoding.UTF8;
info.StandardErrorEncoding = System.Text.UTF8Encoding.UTF8;
}
System.Diagnostics.Process process = System.Diagnostics.Process.Start(info);
if (!info.UseShellExecute)
{
Debug.Log(process.StandardOutput);
Debug.Log(process.StandardError);
}
process.WaitForExit();
process.Close();
}
如果想多个文件一起还原,将上面代码中的这么一句换上即可:
info.Arguments = " revert \"H:\\WorkFiles\\ProjectArt\\Assets\\Art\\(Temporary).meta\" \"H:\\WorkFiles\\ProjectArt\\Assets\\Art\\_3rd.meta\"";
最后封装成 可 还原多文件的 API:
private void SVNRevertFiles(List<string> files)
{
// TortoiseProc.exe /command:log /path:"H:\WorkFiles\ProjectArt\Assets\Art\(Temporary).meta" /closeonend:1
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo("svn");
var revertFiles = string.Join<string>(" ", files);
Debug.Log($"svn revert {revertFiles}");
info.Arguments = $" revert {revertFiles}";
info.CreateNoWindow = false;
info.ErrorDialog = true;
info.UseShellExecute = true;
if (info.UseShellExecute)
{
info.RedirectStandardOutput = false;
info.RedirectStandardError = false;
info.RedirectStandardInput = false;
}
else
{
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.RedirectStandardInput = true;
info.StandardOutputEncoding = System.Text.UTF8Encoding.UTF8;
info.StandardErrorEncoding = System.Text.UTF8Encoding.UTF8;
}
System.Diagnostics.Process process = System.Diagnostics.Process.Start(info);
if (!info.UseShellExecute)
{
Debug.Log(process.StandardOutput);
Debug.Log(process.StandardError);
}
process.WaitForExit();
process.Close();
}