C:\temp>tf folderdiff/?
TF - Team Foundation Version Control Tool
Copyright (c) Microsoft Corporation. All rights reserved.
Displays a visual representation of the differences between files in two server
folders, in a server folder and a local folder, or in two local folders.
tf folderdiff [sourcePath] targetPath [/recursive] [/noprompt]
[/server:serverName:port] [/filter:filter]
[/filterLocalPathsOnly]
[/view:same,different,sourceOnly,targetOnly]
C:\temp>tf folderdiff 1 2/无提示
===========================================================================
Items That Exist Only in C:\temp\1
===========================================================================
C:\temp\1\baz
===========================================================================
Items That Exist Only in C:\temp\2
===========================================================================
C:\temp\2\bar
===========================================================================
Show Items That Have Different Contents
===========================================================================
C:\temp\1\quux -
C:\temp\2\quux
===========================================================================
Summary: 1 folders, 4 files, 1 source, 1 target, 1 different, 0 with errors
===========================================================================
编辑:如果不明显,则默认视图为sourceOnly+targetOnly+different。我有一个名为“foo”的文件,两个文件夹中的内容相同。
我意识到命令行工具本身不是API,但不幸的是,它是这里的最佳选择。否则,您需要自己对树进行爬网——版本控制API中没有文件夹差异。您所得到的只是一个对单个项目进行操作的15+种混乱的方法。
另一方面,如果要比较的所有文件都将被签入,这意味着您可以在不需要任何昂贵的磁盘I/O的情况下进行计算。(tfs存储每个文件内容的哈希)。快速PowerShell示例:
function Compare-TfsDir([string] $dir1, [string] $dir2, [switch] $includeEqual)
{
$dir1 = $dir1.ToLower()
$dir2 = $dir2.ToLower()
filter Decorate($dir)
{
$_ | add-member noteproperty RelativePath $_.ServerItem.ToLower().Replace($dir, "") -passthru |
add-member noteproperty HashString ($_.HashValue | %{ "{0:X2}" -f $_ } | join-string) -passthru
}
$items1 = $tfs.vcs.GetItems($dir1, $tfs.VCS_RecursionType::Full).Items | Decorate $dir1
$items2 = $tfs.vcs.GetItems($dir2, $tfs.VCS_RecursionType::Full).Items | Decorate $dir2
$dirComp = compare -IncludeEqual -Property RelativePath $items1 $items2
"---Tree Comparison---"
$dirComp | ? { $_.SideIndicator -ne "==" } | ft -auto RelativePath, SideIndicator
$both = $dirComp | ? { $_.SideIndicator -eq "==" } | % { $_.RelativePath } | Linq-ToSet
filter InBoth { if ($both.Contains($_.RelativePath)) {$_} }
$contentComp = compare -inc:$includeEqual -Property HashString, RelativePath `
($items1 | InBoth) ($items2 | InBoth)
"---Content Comparison---"
$contentComp | ? { $_.SideIndicator -ne "<=" } | ft -auto RelativePath, SideIndicator
}
不幸的是,如果需要支持本地与服务器的差异,那么这样做需要5倍的代码行。