Team Foundation Version Control Command Reference
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?
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 the some of the topics. However, you can read the Visual Studio 2010 version of these topics.
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:
Use these commands to develop your app under version control with your team:
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:
See also: Suspend Your Work and Manage Your Shelvesets.
Here’s how to check in your code to the team’s codebase:
Use the following commands to isolate risk using branches:
See also: Isolate Risk Using Branches.
Use the following commands to administer your version control system:
See also: Administering Team Foundation Version Control (Visual Studio 2010).
The syntax of each command appears at the top of each reference topic.
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.
You can use itemspecs and versionspecs to specify which items are affected by a command.
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 ?.
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.
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
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.
c:\code\SiteApp\Main>tf get readme.txt /v:C8
-- or --
c:\code\SiteApp\Main>tf get readme.txt /v:8
-- or --
c:\code\SiteApp\Main>tf get readme.txt;8
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.
c:\code\SiteApp\Main>tf get readme.txt;LJulyHotFix
Gets the version of readme.txt that was labeled JulyHotFix.
c:\code\SiteApp\Main>tf get /version:LLastKnownGood
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.
c:\code\SiteApp\Main>tf get /version:D2004-03-22
Updates the workspace to match the codebase as it existed on 3/22/2004 at 00:00 (midnight).
c:\code\SiteApp\Main>tf get /version:D2004-03-22T09:00
Updates the workspace to match the codebase as it existed on 3/22/2004 at 09:00 (9 AM).
Specifies the version in your workspace.
Specifies the version in a specified workspace.
For example: WResolveRIConflicts;PeterW
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 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 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.
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:
Version control commands return the following exit codes:
Partial success; this means at least something, or possibly everything, failed to succeed.
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.