views:

184

answers:

2
+2  A: 

You're just not using the correct syntax when calling it. In this case, it tried to do a diff between your working copy, and the base repository version, of (non-existing) files 14318 and 14317.

What you need to do instead is to use a changeset range in /version, like this:

tf diff $/Foo /version:C14317~C14318 /recursive /format:unified > foo.diff

Note that you can use ~ with any other version specs - labels, dates etc. See here for details.

Pavel Minaev
Thanks! And how would I do a diff on current version (local) and the latest, or unmodified? Many thanks!
Hamish Grubijan
If you don't specify the range, but just a single version, then your local version will be compared to the one you've specified - i.e. `/version:C1000` compares local version to the one after changeset 1000. The most recent version can be specified by `/version:T`. The base version for your local one is `/version:W` (note that all those are also usable in ranges, so `/version:C1000~T` is perfectly valid). As well, you can use local file paths instead of TFS server paths.
Pavel Minaev
I think this does exactly what I want! Why don't people vote your answer up damn it?
Hamish Grubijan
Pavel, for some reason the command is running very slowly on me. The /recursive option slows it down too. There is a lot of code. How do I speed it up? In theory the change-set numbers should be everything I need if I am specifying both. I thought it would be like a dictionary lookup - e.g. fast.
Hamish Grubijan
Without `/recursive`, you'll only get the diff for the directory itself. I would expect it to run slow if you have a lot of code there, because it pretty much has to do a diff on every single file in the tree. Yes, I'd expect it to do a fast dictionary lookup on changeset number, but then multiply that by N files, and it may not be all that fast anymore...
Pavel Minaev
+1  A: 

Here is a PowerShell (V2) script, extending from Pavel's answer, this will be more performant, because we find the files that have changed, then get tf to diff them individually:

Write-Host "Checking if TFS snap-in has been added..." -ForegroundColor green

# Find all TFS snapins.
$snapins = Get-PSSnapin -Registered | Where-Object { $_.Name -like "*TeamFoundation*" } 

foreach($snapin in $snapins)
{ 
    # Add snapin if not already added.
    $exists = Get-PSSnapin | Where-Object { $_.Name -eq $snapin.Name } 
    if (!$exists)
    {
        Write-Host "Adding Snapin " $snapin.Name -ForegroundColor green 
        Add-PSSnapin $snapin.Name 
    }
    else
    {
        Write-Host "Snapin already added." -ForegroundColor green
    }
}



# Get TFS Server object reference.
$tfs_server = Get-TfsServer -Name $/<serverName>/<RepoDir>

# Get list of changed files 
$changes_from_changeset = Get-TfsChangeset -ChangesetNumber 829 | Select -Expand Changes | % { $_.Item.ServerItem }
#$changes_from_changeset

foreach($change in $changes_from_changeset)
{
    &"C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe" diff $change /version:829~T /format:unified
}
Russell
Thanks, what are the pre-requisites if any for running this?
Hamish Grubijan
You will need to have TFS Power tools installed to use TF.exe, and have PowerShell Version 2.0 installed. The Power tools will include a PowerShell snapin, which is used at the start of the script.
Russell