Events
17 Mar, 23 - 21 Mar, 23
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019
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 tf.exe
tool.
To launch the Visual Studio command prompt, from Windows Start, select the Developer Command Prompt for VS2022 or earlier version shortcut.
Note
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:
c:\code\SiteApp\Main\SolutionA>tf get
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:
Use these commands to develop your app under version control with your team:
For more information, see Develop your app in Team Foundation version control.
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.
Use the checkin
command to check in your code to the team's code base:
For more information, see Check in your work to the team's codebase.
Use the resources in the following sections to manage files.
For more information, see Use Source Control Explorer to manage files under version control.
For more information, see View and manage past versions.
For more information, see View and manage past versions.
For more information, see Resolve Team Foundation Version Control conflicts.
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.
Use the following commands to manage your version control system:
For more information, see Configure check-out settings.
Use the following commands to get detailed information about version control commands:
The syntax of each command appears at the top of each reference article.
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.
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.
Some commands support shortcuts. For example, you can call the Delete command with either tf delete
or tf del
.
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./lock:(none|checkin|checkout)
: If you don't specify the /lock
option, the system uses /lock:none
by 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 /login
option verbatim and replace <username>
with the name of the user. If necessary, replace <password>
with the user's password.You can use item specifications and version specifications to specify which items are affected by a command.
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 ?.
A client item specification argument specifies a path to items on a client machine such as:
A server item specification argument specifies a path to items on your Azure DevOps server such as:
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
$/SiteApp/Main/SolutionA/Project1/* /recursive
/noprompt
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.
You use a version specification to specify the version of items affected by a command. To provide a version specification, you can:
Use the /version
option, for example, /version:C44
.
Append the version specification to an item specification with a semicolon, for example, program1.cs;C44
.
When you use the History command or the Difference command, you can specify a range of versions by separating the versions with a tilde, 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:
Type | Syntax | Description | Examples | Result |
---|---|---|---|---|
Changeset | [C]<version-number> |
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. |
Label | L<label> |
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 | D<yyyy-mm-ddTxx:xx> or D<mm/dd/yyyy> or Any .NET Framework-supported format. or 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. |
Current workspace | W |
Specifies the version in your workspace. | - | - |
Specified workspace | W<workspace-name>; <workspace-owner> |
Specifies the version in a specified workspace. | tf get /version:WResolveRIConflicts;PatW |
The example specifies the version in the ResolveRIConflicts workspace that PatW owns. |
Tip | T |
Specifies the most recent version. | - | - |
You can use some common options to modify how a command functions.
Use the /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:
When you use this option, the system:
Suppresses all requests for input:
Redirects output data to the command prompt. For example, you can use this option with the History command. The data is displayed in the command prompt window instead of the History window.
Use the /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.
Important
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.
Use the /lock
option to apply or remove a lock at the same time that you run another command such as Add or Edit.
/lock:(none|checkin|checkout)
The /lock
command uses the following options:
None
: No lock is placed on an item. If a lock is already in place, it gets removed.
Checkin
or Checkout
: A lock is applied. For more information, see Understand lock types.
Note
In a few cases, the lock operation can fail:
You can abbreviate the following options.
Option
Option Alias
/comment
-C
/computer
-M
/delete
-D
/force
-P
/format
-F
/help
-?, -H
/lock
-K
/login
-Y
/newname
-N
/noprompt
-I
/owner
-O
/recursive
-R
/server
-S
/slotmode
-X
/template
-T
/user
-U
/version
-V
/workspace
-W
Version control commands return the following exit codes:
Exit Code
Definition
0
Success.
1
Partial success. At least something, or possibly everything, failed to succeed.
2
Unrecognized command.
100
Nothing succeeded.
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.
Events
17 Mar, 23 - 21 Mar, 23
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Explain how a source control system helps manage files - Training
Explain how a source control system helps manage files
Documentation
Status command (Team Foundation Version Control) - Azure Repos
Use the Team Foundation Version Control (TFVC) Status command to display information about pending changes and pending change candidates.
TFVC workspace command - Azure Repos
Use the Team Foundation Version Control workspace command to create, delete, view, or modify properties and mappings that are associated with a workspace.
Checkin command