1

我在 Windows VM 机器上运行 VisualSVN。VM 崩溃并损坏了映像。恢复旧映像(2007 年)后,我们发现我们的数据备份无法正常运行。因此,我的笔记本电脑(客户端)上有一堆项目(约 20 个),我想将它们推回到现在为空的 VisualSVN 服务器中。

我知道这可以通过简单地手动添加项目文件来完成,但这需要一些时间,因为我不想包含每个文件(即编译文件)。任何建议将不胜感激。

4

1 回答 1

1

不幸的是,我没有为您提供完全自动化的解决方案,但确定存储库中版本控制的文件的一种方法是使用带有命令行工具的list命令:

svn.exe list -R

该命令将递归列出当前目录中由 SVN 版本控制的所有文件。获得该列表后,您可以将它们复制到另一个目录并将它们批量提交到新存储库。

将该命令与一些Powershell魔法相结合可能会使重新创建存储库的任务尽可能轻松。

更新:

我花了一些时间玩 Powershell 并想出了如何做到这一点。例如,我将要解释的原始存储库目录是 C:\source_repos\,而新的存储库目录是 C:\dest_repos\。

  1. 打开命令提示符。这可以通过附件开始菜单文件夹或通过在 Vista/Win7 中的搜索框中运行“cmd”或在 WinXP 中运行...来完成。
  2. 从命令提示符运行以下命令:

    cd C:\source_repos\
    echo File > filelist.csv
    svn.exe list -R >> filelist.csv
    

    第二个命令创建 filelist.csv,第一行包含单词“File”。第三个命令运行 svn list 命令并将输出重定向到附加到 filelist.csv。此时,filelist.csv 应该在第一行有“文件”,然后是在单独的行上列出的 svn 目录中的每个版本的文件。

  3. 获取下面的代码并将其粘贴到名为 reposcope.ps1 的文件中:

    # 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

  4. 打开 Powershell(可以在 Vista/Win7 的附件或 WinXP 的 Powershell 中找到)。转到保存上述脚本的目录并运行它。如果您收到提及“在此系统上禁用脚本执行”的错误,请运行

    Set-ExecutionPolicy RemoteSigned
    

    在 powershell 中以使本地脚本无需签名即可运行。

那应该这样做。如果一切顺利,您应该能够将所有文件转到新存储库和C:\dest_repos\它们。svn addsvn commit

如果您对我试图解释的内容有任何疑问或遇到任何奇怪的错误,请告诉我。我对脚本进行了表面测试,但很可能我忘记了一些边缘情况。

祝您的存储库恢复顺利!

于 2010-03-04T20:36:14.797 回答