TFS:检查本地文件是否是脚本中的最新版本

问题描述 投票:2回答:1

参考:Visual Studio Team Foundation Server 2015:如果本地文件是否等于服务器上的最新版本,如何在TFS源代码控制下从批处理或Powershell脚本中检查给定文件?

tfs
1个回答
4
投票

您可以使用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"

1:使用get /preview,它将预览是否可以获得更新的版本。

& cmd /c "`"$tfExe`" get $file /preview"

结果如果最新:

All files are up to date.

结果如果不是最新的:

D:\MyProjects\Project1\Logic:
Replacing Program.cs

Get Documentation Link


2:使用difference /format:Briefstatus,它会告诉你本地是否存在差异,但没有待定的更改

& cmd /c "`"$tfExe`" difference $file /format:Brief"
& cmd /c "`"$tfExe`" status $file"

结果如果最新:

Comparing local to latest: D:\MyProjects\Project1\Logic\Program.cs
There are no pending changes.

结果如果不是最新的:

Comparing local to latest: D:\MyProjects\Project1\Logic\Program.cs
Program.cs: files differ
There are no pending changes.

Difference Documentation Link

Status Documentation Link


3:使用info,它将显示本地变更集和服务器变更集,您可以看到它们是否不同。

& cmd /c "`"$tfExe`" info $file"

结果:

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

Info/Properties Documentation Link


还有LocalVersions,它将告诉您文件的本地变更集,以及History,它将显示文件的所有变更集。

© www.soinside.com 2019 - 2024. All rights reserved.