Use Team Foundation version control commands
Team Services | TFS 2015 | Visual Studio 2015 | Visual Studio 2013
You can use version control commands to do nearly all tasks you can do in Visual Studio, and also several tasks that can’t be done in Visual Studio. You can use the tf.exe tool to run version control commands from a command prompt or within a script.
What do you want to do?
Run a command
To launch the Visual Studio command prompt, from Windows Start, choose Microsoft Visual Studio 2012, Visual Studio Tools, and then choose one of the Command Prompt shortcuts.
In most cases, you run the version control command in the context of a directory that is 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:
We are not currently republishing some of the topics. However, you can read the Visual Studio 2010 version of these topics.
Set up your dev machine and manage workspaces
Your workspace is a local copy of your team’s codebase. Because it is a local copy on your dev machine, you can develop and test your code in isolation until you are ready to check in your work. Here are some commands to manage your workspace:
Proxy Command (Visual Studio 2010)
Workfold Command (Visual Studio 2010)
Workspace Command (Visual Studio 2010)
Workspaces Command (Visual Studio 2010)
Develop your app
Use these commands to develop your app under version control with your team:
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) (Visual Studio 2010)
Gets (downloads) the latest or a specified version of one or more files or folders from Team Foundation Server to the workspace.
Rename Command (Team Foundation Version Control) (Visual Studio 2010)
Displays information about pending changes to files and folders items in one or more workspaces, or in a shelveset.
Discards one or more pending changes to files or folders.
Undelete Command (Visual Studio 2010)
Suspend your work
For a variety of reasons, sometimes you need to set aside some or all of your work in progress. To suspend and resume your work, and to manage your shelvesets, use these commands:
Shelve Command (Visual Studio 2010)
Shelvesets Command (Visual Studio 2010)
Unshelve Command (Visual Studio 2010)
See also: Suspend your work and manage your shelvesets.
Contribute your work
Here’s how to check in your code to the team’s codebase:
Checks in pending changes to files or folders to the server.
Manage files and solve problems
View and Manage Version Control Files and Folders
Properties (or Info) Command (Visual Studio 2010)
Property Command (not documented)
Dir Command (Visual Studio 2010)
Destroy Command (Team Foundation Version Control) (Visual Studio 2010)
LocalVersions Command (Visual Studio 2010)
View and Manage Past Versions
Changeset Command (Visual Studio 2010)
Displays the revision history of one or more files or folders.
Label Command (Team Foundation Version Control) (Visual Studio 2010)
Labels Command (Visual Studio 2010)
Rollback Command (Team Foundation Version Control) (Visual Studio 2010)
Unlabel Command (Visual Studio 2010)
View Command (Visual Studio 2010)
See also: View and manage past versions
Compare Folders and Files
Difference Command (Visual Studio 2010)
Folderdiff Command (Visual Studio 2010)
See also: View and manage past versions
Resolve File Conflicts
Resolve Command (Visual Studio 2010)
Work with Version Control Locks
Lock Command (Visual Studio 2010)
See also: Work with version control locks.
Use the following commands to isolate risk using branches:
Branch Command (Visual Studio 2010)
Branches Command (Visual Studio 2010)
Merge Command (Visual Studio 2010)
Merges Command (Visual Studio 2010)
Administer Version Control
Use the following commands to administer your version control system:
Configure Command (Visual Studio 2010)
Permission Command (Visual Studio 2010)
See also: Administering Team Foundation Version Control (Visual Studio 2010).
Get Help on Version Control Commands
Use the following commands to get more information about version control commands:
Help Command (Team Foundation Version Control) (Visual Studio 2010)
Msdn Command (Visual Studio 2010)
Understand command syntax
The syntax of each command appears at the top of each reference topic.
Required and optional arguments
Non-bracketed arguments are required. [Brackets] indicate optional arguments that are not required to complete a command. However, some optional arguments have defaults that are applied to the command even if you do not specify the option.
When options are separated by a pipe (|), you can specify one of the options.
Verbatim and replaceable arguments
Bold items are options that you include verbatim. Italicized items 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 tf del.
For example, the Checkout command:
tf checkout [/lock:( none|checkin|checkout)] [/recursive] itemspec [/login: username,[ password]]
Let’s review the arguments from this example:
itemspec: You must replace this argument with an itemspec that specifies the items you are checking out.
/lock:(none|checkin|checkout): You are not required to specify the /lock option. If you do not specify it, then the system by default specifies /lock:none. Otherwise, you can specify one of the lock options.
The following arguments are optional and if you do not supply them, none of their effects apply to the command:
/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, replace username with the name of the user, and if necessary, you can supply the password.
Specify the items affected by a command
You can use itemspecs and versionspecs to specify which items are affected by a command.
Use an itemspec argument to specify affected items
You use an itemspec (item specification) to specify the items affected by a command. You can specify items either on a client machine or on your Team Foundation Server. You can use wildcard characters such as \* and ?.
Client itemspec arguments
A client itemspec 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 or multiple files (for example, c:\code\SiteApp\Main\SolutionA\*.cs. You can also specify UNC paths such as \\myshare\code\SiteApp\Main.
Server itemspec arguments
A server itemspec argument specifies a path to items on your Team Foundation Server such as a folder (for example, $/SiteApp/Main/SolutionA) a file (for example, $/SiteApp/Main/SolutionA/Project1/program.cs or multiple files (for example, $/SiteApp/Main/SolutionA/*.cs.
You typically use server itemspec arguments when you need run a command on items not on the client machine. For example, you are working on a dev machine and need to get some revision history data about some items that are in a team project collection you don’t work in:
c:\>tf history /collection:http://fabrikam-3:8080/tfs/DefaultCollection $/SiteApp/Main/SolutionA/Project1/* /recursive /noprompt
Multiple itemspec arguments
For some commands, you can specify multiple itemspec arguments. For example:
c:\code\SiteApp\Main\SolutionA\Project1\>tf checkout program1.cs program2.c
Checks out program.cs and program2.c.
Use a versionspec argument to specify affected versions of items
You use a versionspec (version specification) to specify the version of items affected by a command. To provide a versionspec you can:
Use the /version option. For example: /version:C44.
Append the versionspec to an itemspec with a semicolon. For example: program1.cs;C44.
c:\code\SiteApp\Main\SolutionA>tf history /noprompt * /recursive /v:D4/12/2012~D4/24/2012
Use the following syntax to specify a versionspec.
Specifies items based on a changeset number. If an item that is in scope was not modified in the specified changeset, the system takes the latest version of the item that occurred before the specified changeset.
-- or --
-- or --
If readme.txt was modified in changeset 8, gets that version of the file. Otherwise, gets the most recent version of readme.txt before version 8.
Specifies items to which label was applied.
Gets the version of readme.txt that was labeled JulyHotFix.
Retrieves the version of all labeled items (and deletes those items not labeled) in the workspace as they existed when the changeset labeled as LastKnownGood was created, for example, perhaps 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 created on a specified date and time.
Updates the workspace to match the codebase as it existed on 3/22/2004 at 00:00 (midnight).
Updates the workspace to match the codebase as it existed on 3/22/2004 at 09:00 (9 AM).For more information about .NET Framework-supported date and time formats see DateTime.
Specifies the version in your workspace.
Specifies the version in a specified workspace.
For example: WResolveRIConflicts;PeterW
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.
Use the /noprompt option to suppress requests for data input and redirect output data to the command prompt window
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 because the command proceeds without intervention by a user, and the data is available for the script to perform operations such as parsing or capturing.
When you use this option, the system:
Suppresses all requests for input:
Questions are not asked in the command prompt window. For example, when you use the Undo command with this option, the system does not prompt you to confirm if you want to proceed with undoing the changes.
Windows and dialog boxes are not presented. For example, you use this option with the Checkin command. Instead of displaying the Check In dialog box for you to confirm your options (which items you want to check in or which work items to associate), the system proceeds with the check in without confirmation.
Use /login option to specify credentials when running a command
Use the /login option to specify the Team Foundation Server user account to run a command. This option can be useful when you are working at the machine of another team member.
For example, Julia is working with Peter at his dev machine. She uses the Lock command to unlock a file that she locked earlier:
c:\code\SiteApp\Main> tf lock /lock:none program.cs /login:JuliaI,JuliaPassword
If she wants to avoid having her password appear in the command prompt, she can enter the command without the password:
c:\code\SiteApp\Main> tf lock /lock:none program.cs /login:JuliaI
After she enters this command, the system then prompts her to type her password in a dialog box that masks her input.
Use the /lock option to apply or remove a lock
As a best practice, use the /lock option with discretion and notify your teammates why you are locking an item, and when you plan to remove the lock.
None: No lock is placed on an item. If a lock is already in place, it is removed.
Checkin or Checkout: Applies a lock. 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 will fail.
- The system ignores this switch if there is already a pending change to the item. 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; this means at least something, or possibly everything, failed to succeed.
c:\code\SiteApp\Main\SolutionA\Project1\>tf checkout program1.cs program2.c
If one of the files you are trying to check out does not exist on the server, the command returns 1 to indicate partial success.