Use Team Foundation version control commands
Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019 | TFS 2018
Visual Studio 2019 | Visual Studio 2022
You can use version control commands to do nearly all Team Foundation Version Control (TFVC) tasks that you can do in Visual Studio. You can also use version control commands to do several tasks that can't be done in Visual Studio. To run version control commands from a command prompt or within a script, you use the
Run a command
To launch the Visual Studio command prompt, from Windows Start, select the Developer Command Prompt for VS2022 or earlier version shortcut.
For Visual Studio 2019 and later versions, the
tf.exe binary is no longer in a fixed location in the Visual Studio install path as in some previous releases, for example,
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE. If your script uses
tf.exe, don't hard-code a path to the file based on the Visual Studio install path.
In most cases, you run the version control command in the context of a directory that's mapped in the workspace. For example,
$/SiteApp/Main/ is mapped to
c:\\code\\SiteApp\\Main\\. To get the latest version of all items in the workspace, use the following command:
Set up your development machine and manage workspaces
Your workspace is a local copy of your team's codebase. Because it's a local copy on your development machine, you can develop and test your code in isolation until you're ready to check in your work. Here are some commands to manage your workspace:
For more information, see the following resources:
Develop your app
Use these commands to develop your app under version control with your team:
- Add command: Adds files and folders to version control.
- Checkout (or Edit) command: Checks out a file and changes its pending change status to edit.
- Delete command (Team Foundation Version Control): Removes files and folders from the Azure DevOps server and deletes them from the disk.
- Get command: Gets (downloads) the latest version or a specified version of one or more files or folders from Azure DevOps Server to the workspace.
- Rename command (Team Foundation Version Control): Changes the name or path of a file or folder.
- Status command: Displays information about pending changes to files and folders in workspaces or in a shelveset.
- Undo command: Discards specified pending changes to files or folders.
- Undelete command: Restores items that were previously deleted.
For more information, see Develop your app in Team Foundation version control.
Suspend your work
For various reasons, sometimes you need to set aside some or all of your in-progress work. To suspend and resume your work, and to manage your shelvesets, use these commands:
For more information, see Suspend your work and manage your shelvesets.
Contribute your work
checkin command to check in your code to the team's code base:
- Checkin command: Checks in pending changes to files or folders to the server.
For more information, see Check in your work to the team's codebase.
Manage files and solve problems
Use the resources in the following sections to manage files.
View and manage version control files and folders
- Properties (or Info) command: Displays information about items in version control.
- Dir command: Displays the contents of the version control server.
- Destroy command (Team Foundation Version Control): Permanently deletes version-controlled files.
- LocalVersions command: Displays the versions of workspace items.
For more information, see Use Source Control Explorer to manage files under version control.
View and manage past versions
- Changeset command: Changes or displays changeset attributes.
- History command: Displays the revision history of files or folders.
- Label command (Team Foundation Version Control): Attaches or removes labels from files or folders.
- Labels command: Displays information about labels that are in use in the server.
- Rollback command (Team Foundation Version Control): Rolls back the effects of changesets.
- Unlabel command: Removes an item from an existing label in the server.
- View command: Retrieves a specified version of a file and displays it.
For more information, see View and manage past versions.
Compare folders and files
- Difference command: Compares differences between files and shelvesets.
- Folderdiff command: Compares differences between files in two folders.
For more information, see View and manage past versions.
Resolve file conflicts
- Resolve command: Resolves conflicts between items in your workspace and on the server.
For more information, see Resolve Team Foundation Version Control conflicts.
Work with version control locks
- Lock command: Locks or unlocks files and folders.
For more information, see Work with version control locks.
Use the following commands to isolate risk by using branches:
For more information, see Use branches to isolate risk in Team Foundation Version Control.
Administer version control
Use the following commands to manage your version control system:
For more information, see Configure check-out settings.
Get help on version control commands
Use the following commands to get detailed information about version control commands:
Understand command syntax
The syntax of each command appears at the top of each reference article.
Required and optional arguments
Non-bracketed arguments are required. [Brackets] indicate optional arguments that aren't required to complete a command. However, some optional arguments have defaults that are applied to the command even if you don't specify the option.
When options are separated by a pipe (|), you can specify one of the options.
Verbatim and replaceable arguments
Items that aren't enclosed in brackets are options that you include verbatim. Items enclosed in angle brackets (< and >) are arguments that you must replace with actual characters to perform a command.
Command shortcuts and aliases
Some commands support shortcuts. For example, you can call the Delete command with either
tf delete or
For example, consider the Checkout command:
tf checkout [/lock:( none|checkin|checkout)] [/recursive] <item-spec> [/login: <username>, [<password>]]
This example includes the following arguments:
<item-spec>: You must replace this argument with an item specification that identifies the items that you're checking out.
- The following arguments are optional. If you don't supply them, none of their effects apply to the command:
/lock:(none|checkin|checkout): If you don't specify the
/lockoption, the system uses
/lock:noneby default. Otherwise, you can specify one of the other lock options.
/recursive: If you want to recursively check out multiple items in a folder, you must specify this option verbatim.
/login:<username>, <password>: If you want to run the command as another user, you must specify the
/loginoption verbatim and replace
<username>with the name of the user. If necessary, replace
<password>with the user's password.
Specify the items affected by a command
You can use item specifications and version specifications to specify which items are affected by a command.
Use an item specification argument to specify affected items
You use an item specification to specify the items affected by a command. You can specify items either on a client machine or on your Azure DevOps server. You can use wildcard characters such as * and ?.
Client item specification arguments
A client item specification argument specifies a path to items on a client machine such as:
- A folder, for example, c:\code\SiteApp\Main\SolutionA\.
- A file, for example, c:\code\SiteApp\Main\SolutionA\Project1\program.cs.
- Multiple files, for example, c:\code\SiteApp\Main\SolutionA\*.cs.
- A universal naming convention (UNC) path, such as \\myshare\code\SiteApp\Main.
Server item specification arguments
A server item specification argument specifies a path to items on your Azure DevOps server such as:
- A folder, for example, $/SiteApp/Main/SolutionA.
- A file, for example, $/SiteApp/Main/SolutionA/Project1/program.cs.
- Multiple files, for example, $/SiteApp/Main/SolutionA/*.cs.
You typically use server item specification arguments when you need to run a command on items that aren't on the client machine. For example, say you're working on a development machine. If you need to get some revision history data about some items that are in a project collection that you don't work in, you can use the following command:
c:\>tf history /collection:https://fabrikam-3:8080/tfs/DefaultCollection
Multiple item specification arguments
For some commands, you can specify multiple item specification arguments, for example:
c:\code\SiteApp\Main\SolutionA\Project1\>tf checkout program1.cs program2.c
This command checks out program.cs and program2.c.
Use a version specification argument to specify affected versions of items
You use a version specification to specify the version of items affected by a command. To provide a version specification, you can:
/versionoption, for example,
Append the version specification to an item specification with a semicolon, for example,
c:\code\SiteApp\Main\SolutionA>tf history /noprompt * /recursive /v:D4/12/2022~D4/24/2022
Use the following syntax to specify a version specification:
|Specifies items based on a changeset number. If an item that's in scope wasn't modified in the specified changeset, the system takes the latest version of the item that occurred before the specified changeset. You can omit
C if you specify only a number.
tf get readme.txt /v:C8
tf get readme.txt /v:8
tf get readme.txt;8
|If readme.txt was modified in changeset 8, the example code gets that version of the file. Otherwise, it gets the most recent version of readme.txt before version 8.
|Specifies items that a label is applied to.
tf get readme.txt;LJulyHotFix
tf get /version:LLastKnownGood
|The first example gets the version of readme.txt that was labeled JulyHotFix. The second retrieves the version of all labeled items (and deletes those items not labeled) in the workspace as they existed when the changeset labeled LastKnownGood was created. You might use the code in the second example as part of an automated build process.
|Date and time
Any .NET Framework-supported format.
Any of the date formats supported on the local machine.
|Specifies a changeset that was created on a specified date at a specific time.
tf get /version:D2022-03-22
tf get /version:D2022-03-22T09:00
|The first example updates the workspace to match the codebase as it existed on March 22, 2022 at midnight. The second updates the workspace to match the codebase as it existed on March 22, 2022 at 9:00 AM. For more information about .NET Framework-supported date and time formats, see DateTime and Standard date and time format strings.
|Specifies the version in your workspace.
|Specifies the version in a specified workspace.
tf get /version:WResolveRIConflicts;PatW
|The example specifies the version in the
ResolveRIConflicts workspace that
|Specifies the most recent version.
Use options to modify how a command functions
You can use some common options to modify how a command functions.
/noprompt option to suppress data input requests and redirect output data
/noprompt option to suppress requests for data input and redirect output data to the command prompt window. This option can be useful when you need to use version control commands in a script where:
- The command proceeds without intervention by a user.
- The data is available for the script to perform operations on, such as parsing or capturing.
When you use this option, the system:
Suppresses all requests for input:
- Questions aren't asked in the command prompt window. For example, when you use the Undo command with this option, the system doesn't prompt you to confirm whether you want to undo the changes.
- Windows and dialog boxes aren't displayed. For example, you can use this option with the Checkin command. The system doesn't display the Check In dialog box for you to confirm items and associated work items. Instead, the system checks in the items without confirmation.
/login option to specify credentials
/login option to specify the Azure DevOps server user account to run a command in. This option can be useful when you work at the machine of another team member.
For example, say you're working at your team member's development machine. You use the Lock command to unlock a file that you locked earlier:
c:\code\SiteApp\Main> tf lock /lock:none program.cs /login:<username>,<password>
If you want to avoid having your password appear in the command prompt, you can enter the command without the password:
c:\code\SiteApp\Main> tf lock /lock:none program.cs /login:<username>
After you enter this command, the system prompts you to enter your password in a dialog box that masks your input.
/lock option to apply or remove a lock
As a best practice, use the
/lock option with discretion. Inform your teammates why you're locking an item and when you plan to remove the lock.
/lock command uses the following options:
None: No lock is placed on an item. If a lock is already in place, it gets removed.
Checkout: A lock is applied. For more information, see Understand lock types.
In a few cases, the lock operation can fail:
- If any other users have locked any of the specified items, the lock operation fails.
- If there's already a pending change to the specified item, the system ignores this switch. In this case, you must use the Lock command to change a lock on an item.
Use option shortcuts
You can abbreviate the following options.
Understand exit codes
Version control commands return the following exit codes:
Partial success. At least something, or possibly everything, failed to succeed.
For example, say you run the following command:
c:\code\SiteApp\Main\SolutionA\Project1\>tf checkout program1.cs program2.c
If one of the files you're trying to check out doesn't exist on the server, the command returns 1 to indicate partial success.