参考:Visual Studio Team Foundation Server 2015:如何从批处理或 Powershell 脚本中检查 TFS 源代码控制下给定文件的本地文件是否等于服务器上的最新版本?
您可以使用 Visual Studio 附带的 tf.exe。以下是使用 PowerShell 的一些不同选项。这也可以通过一些更改来批量编写。
假设如下:
# Change directory to the folder containing your file.
Set-Location "D:\MyProjects\Project1\Logic"
# File to evaluate
$file = "Program.cs"
# Using the Visual Studio 2015 Common Tools System Variable to find tf.exe
$tfExe = "$env:VS140COMNTOOLS\..\IDE\TF.exe"
Run Code Online (Sandbox Code Playgroud)
1:使用get /preview,会预览是否可以获得更新的版本。
& cmd /c "`"$tfExe`" get $file /preview"
Run Code Online (Sandbox Code Playgroud)
结果(如果最新):
All files are up to date.
Run Code Online (Sandbox Code Playgroud)
结果如果不是最新的:
D:\MyProjects\Project1\Logic:
Replacing Program.cs
Run Code Online (Sandbox Code Playgroud)
2:difference /format:Brief与 一起使用status,它会告诉您本地是否存在差异,但没有挂起的更改
& cmd /c "`"$tfExe`" difference $file /format:Brief"
& cmd /c "`"$tfExe`" status $file"
Run Code Online (Sandbox Code Playgroud)
结果(如果最新):
Comparing local to latest: D:\MyProjects\Project1\Logic\Program.cs
There are no pending changes.
Run Code Online (Sandbox Code Playgroud)
结果如果不是最新的:
Comparing local to latest: D:\MyProjects\Project1\Logic\Program.cs
Program.cs: files differ
There are no pending changes.
Run Code Online (Sandbox Code Playgroud)
3:使用info,会显示本地变更集和服务器变更集,你可以看看它们是否不同。
& cmd /c "`"$tfExe`" info $file"
Run Code Online (Sandbox Code Playgroud)
结果:
Local information:
Local path : D:\MyProjects\Project1\Logic\Program.cs
Server path: $/MyProjects/Project1/Logic/Program.cs
Changeset : 2842
Change : none
Type : file
Server information:
Server path : $/MyProjects/Project1/Logic/Program.cs
Changeset : 2845
Deletion ID : 0
Lock : none
Lock owner :
Last modified: Friday, December 15, 2017 4:32:57 PM
Type : file
File type : utf-8
Size : 2835
Run Code Online (Sandbox Code Playgroud)
还有LocalVersions,它会告诉您文件的本地变更集,以及History,它将显示文件的所有变更集。
| 归档时间: |
|
| 查看次数: |
916 次 |
| 最近记录: |