Search code examples
tfstfvc

Get all versions of the file in all history, changesets


Is there a tf command that will extract all versions of config.json file, from all changesets?

I want to see how it was changed in the course of development.

I use Team Foundation Server 2012 (v11).


Solution

  • You'll need to script that... Using PowerShell or something similar.

    Use:

    tf history /collection:{{https://server/collection}} {{$/project/path/file}} /format:brief /noprompt
    

    to grab all unique changesets for the file. Extract the numbers for each line in the table. A regex is an easy way... ^\d+ on each line should grab the number from the start of each line.

    Then create a local workspace to get the copies of the file, the basic structure should look like this, but you'll need to script the loop and variable insertions:

    md temp
    cd temp
    tf workspace /new /noprompt temporary-workspace /collection:{{https://server/collection}}
    tv workfold /map $/project/path . /collection:{{https://server/collection}}
    
    ## foreach {{changesetnumber}} in {{history}}
    tf get /version:c{{changesetnumber}} /overwrite /force /noprompt {{$/project/path/}}config.json 
    
    copy config.json ..\config.json.{{changesetnumber}}
    ## end forach
    
    tf workspace /delete temporary-workspace
    

    That should create a numbered copy of the file for each changeset.

    The powershell script below works for me, but is still a bit rough:

    $tf = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\TF.exe"
    $collectionUri = "https://dev.azure.com/jessehouwing"
    $path = '$/agile2017'
    $file = "xxxxxxx"
    
    $history = & $tf history /collection:$collectionUri $path/$file /format:brief /noprompt
    $changesets = $history | %{ Select-String -InputObject $_ -Pattern "^\d+" }
    $changesets = $changesets.Matches | %{ $_.value }
    
    cd $env:temp
    md temporary-workspace -force
    md history -Force
    cd temporary-workspace
    & $tf workspace /new /noprompt temporary-workspace /collection:$collectionUri
    & $tf workfold /map $path . 
    
    foreach ($changeset in $changesets)
    {
        & $tf get /version:c$changeset /overwrite /force /noprompt $path/$file 
        copy "$file" "..\history\$file.$changeset" -Force
    }
    
    & $tf workspace /delete temporary-workspace
    cd ..
    rd temporary-workspace -Recurse