Question

I used to use a different source control tool and it allowed me to get a "diff report": all the changes made to a file between version X and version Y (including lines added/removed between each version, which could be many versions) in one text file. It was pretty handy for situations where you are pretty sure that some code used to be in your file but now it's not (handy for when your BA says to add something and you're thinking "didn't I take that out?!").

The advantage here is that you get one text file that has all the changes to a codebase that you can then search. This is equivalent to doing a compare on every version (10 to 9, 9 to 8 etc) and then saving the results of every compare to a text file.

I don't see any easy way to do this in TFS. Is there a plugin/powertool that does this? The google gave me nothing.

Was it helpful?

Solution 2

Pavel got me going in the right direction, but the script I ended up with was a lot more complex. And still might not be correct. I had to account for filename changes.

$snapin = get-pssnapin  | select-string "Microsoft.TeamFoundation.PowerShell"

if ($snapin -eq $null) { 
Write-Host "loading snap in..."     
     Add-PSSnapin Microsoft.TeamFoundation.PowerShell 
  }

$fileName = $args[0]  Write-Host "// File name " $fileName 
$results = @(Get-TfsItemHistory $fileName )  | select changesetid, @{name="Path"; expression={$_.changes[0].item.serveritem}}

$i = 0

$cmdArray = @() 

do {   
   if ( $results[$i+1] -ne "" ) {   
   $cmdArray +=  "tf diff ""{0};{1}"" ""{2};{3}""  /format:unified" -f $results[$i].Path, $results[$i].ChangeSetId, $results[$i+1].Path, $results[$i+1].ChangeSetId     
   } ; 
    $i++ 
} until ($i -ge ($results.length - 1))

foreach ($cmd in $cmdArray) {   
   #Write-Host "// " $cmd   
   iex $cmd  }

OTHER TIPS

I'm not aware of any out-of-the-box solution. However, it isn't hard to make one yourself if you have TFS Power Toys and PowerShell. Try this in PowerShell:

Add-PSSnapin Microsoft.TeamFoundation.PowerShell

Get-TfsItemHistory foo.cs | foreach {
  tf diff "foo.cs;C$($_.ChangesetId)" `
          "foo.cs;C$($_.ChangesetId - 1)" `
          /format:unified
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top