我在 Windows VM 机器上运行 VisualSVN。VM 崩溃并损坏了映像。恢复旧映像(2007 年)后,我们发现我们的数据备份无法正常运行。因此,我的笔记本电脑(客户端)上有一堆项目(约 20 个),我想将它们推回到现在为空的 VisualSVN 服务器中。
我知道这可以通过简单地手动添加项目文件来完成,但这需要一些时间,因为我不想包含每个文件(即编译文件)。任何建议将不胜感激。
我在 Windows VM 机器上运行 VisualSVN。VM 崩溃并损坏了映像。恢复旧映像(2007 年)后,我们发现我们的数据备份无法正常运行。因此,我的笔记本电脑(客户端)上有一堆项目(约 20 个),我想将它们推回到现在为空的 VisualSVN 服务器中。
我知道这可以通过简单地手动添加项目文件来完成,但这需要一些时间,因为我不想包含每个文件(即编译文件)。任何建议将不胜感激。
不幸的是,我没有为您提供完全自动化的解决方案,但确定存储库中版本控制的文件的一种方法是使用带有命令行工具的list命令:
svn.exe list -R
该命令将递归列出当前目录中由 SVN 版本控制的所有文件。获得该列表后,您可以将它们复制到另一个目录并将它们批量提交到新存储库。
将该命令与一些Powershell魔法相结合可能会使重新创建存储库的任务尽可能轻松。
更新:
我花了一些时间玩 Powershell 并想出了如何做到这一点。例如,我将要解释的原始存储库目录是 C:\source_repos\,而新的存储库目录是 C:\dest_repos\。
cd C:\source_repos\
echo File > filelist.csv
svn.exe list -R >> filelist.csv
第二个命令创建 filelist.csv,第一行包含单词“File”。第三个命令运行 svn list 命令并将输出重定向到附加到 filelist.csv。此时,filelist.csv 应该在第一行有“文件”,然后是在单独的行上列出的 svn 目录中的每个版本的文件。
# Assumptions / Notes:
# - No crazy file names with "\" in them!
# - A file named filelist.csv was created by running:
# svn.exe list -R >> filelist.csv
# and is in the base directory of the source repository.
# - The first line of filelist.csv is "File" without quotes, this is
# important for the Import-Csv command
# - If you get an error about permissions when you try to run the script,
# use the command "Set-ExecutionPolicy RemoteSigned" in the powershell
# Source & destination repository directories
$src = "C:\source_repos\"
$dest = "C:\dest_repos\"
# Get current directory
$origdir = Get-Location
# Goto source repository directory
Set-Location $src
# Check if destination repository directory exists, if not create it
if (![IO.Directory]::Exists($dest)) {
[IO.Directory]::CreateDirectory($dest)
}
# Import filelist.csv created with these commands at a command prompt:
# cd C:\source_repos
# echo File > filelist.csv
# svn.exe list -R >> filelist.csv
$filelist = Import-Csv filelist.csv
# Go through each line in the filelist
foreach ($line in $filelist) {
# Concatenate the filename with the source and destination directories
$srcfile = [String]::Concat($src, $line.File)
$destfile = [String]::Concat($dest, $line.File)
# If the destination file is a directory and it doesn't exist create it
# Otherwise copy the source file to the destination.
if ($destfile.EndsWith("\")) {
if (![IO.Directory]::Exists($destfile)) {
[IO.Directory]::CreateDirectory($destfile)
}
} else {
Copy-Item $srcfile $destfile
}
}
# Go back to the original directory
Set-Location $origdir
您需要为每次运行
修改$src
和变量。$dest
Set-ExecutionPolicy RemoteSigned
在 powershell 中以使本地脚本无需签名即可运行。
C:\dest_repos\
它们。svn add
svn commit
如果您对我试图解释的内容有任何疑问或遇到任何奇怪的错误,请告诉我。我对脚本进行了表面测试,但很可能我忘记了一些边缘情况。
祝您的存储库恢复顺利!