Use Team Foundation version control commands

Visual Studio Team Foundation Server 2013

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:

 Copy imageCopy Code
c:\code\SiteApp\Main\SolutionA>tf get
NoteNote

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)

See also: Set up Team Foundation Version Control on your dev machine, Create and work with workspaces

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 (Visual Studio 2010)

Get command

Gets (downloads) the latest or a specified version of one or more files or folders from Team Foundation Server to the workspace.

Rename Command (Visual Studio 2010)

Status command

Displays information about pending changes to files and folders items in one or more workspaces, or in a shelveset.

Undo command

Discards one or more pending changes to files or folders.

Undelete Command (Visual Studio 2010)

See also: Develop your app in Team Foundation version control

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:

Checkin command

Checks in pending changes to files or folders to the server.

See also: Check in your work to the team's codebase

Manage files and solve problems

View and Manage Version Control Files and Folders
Properties Command (Visual Studio 2010)

Property Command (not documented)

Dir Command (Visual Studio 2010)

Destroy Command (Visual Studio 2010)

LocalVersions Command (Visual Studio 2010)

See also: Use Source Control Explorer to manage files under version control

View and Manage Past Versions
Changeset Command (Visual Studio 2010)

History command

Displays the revision history of one or more files or folders.

Label Command (Visual Studio 2010)

Labels Command (Visual Studio 2010)

Rollback Command (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)

See also: Resolve Team Foundation Version Control conflicts.

Work with Version Control Locks

Lock Command (Visual Studio 2010)

See also: Work with version control locks.

Isolate risk

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)

See also: Use branches to isolate risk in Team Foundation Version Control.

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: Managing 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 (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.

Exclusive arguments

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.

Example

For example, the Checkout command:

 Copy imageCopy Code
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:

     Copy imageCopy Code
    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:

     Copy imageCopy Code
    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.

    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:
     Copy imageCopy Code
    c:\code\SiteApp\Main\SolutionA>tf history /noprompt * /recursive /v:D4/12/2012~D4/24/2012

    Use the following syntax to specify a versionspec.

    Type

    Syntax

    Description

    Changeset

    [C]n

    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.

    TipTip

    You can omit the C if you specify only a number.

    Examples

     Copy imageCopy Code
    c:\code\SiteApp\Main>tf get readme.txt /v:C8

    -- or --

     Copy imageCopy Code
    c:\code\SiteApp\Main>tf get readme.txt /v:8

    -- or --

     Copy imageCopy Code
    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.

    Label

    Llabel

    Specifies items to which label was applied.

    Examples

     Copy imageCopy Code
    c:\code\SiteApp\Main>tf get readme.txt;LJulyHotFix

    Gets the version of readme.txt that was labeled JulyHotFix.

     Copy imageCopy Code
    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

    Dyyyy-mm-ddTxx:xx

    -or-

    Dmm/dd/yyyy

    -or-

    Any .NET Framework-supported format.

    -or-

    Any of the date formats supported on the local machine.

    Specifies a changeset created on a specified date and time.

    Examples

     Copy imageCopy Code
    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).

     Copy imageCopy Code
    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).

    For more information about .NET Framework-supported date and time formats see DateTime and Standard Date and Time Format Strings.

    Workspace (current)

    W

    Specifies the version in your workspace.

    Workspace (specified)

    Wworkspacename; workspaceowner

    Specifies the version in a specified workspace.

    For example: WResolveRIConflicts;PeterW

    Tip

    T

    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.

  • Redirects output data to the command prompt. For example, you use this option with the History command. The data is displayed in the command prompt window instead of the History window.

  • 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:

     Copy imageCopy Code
    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:

     Copy imageCopy Code
    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

    Important noteImportant

    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.

    Use the /lock option to apply or remove a lock at the same time you run another command such as Add or Edit.

     Copy imageCopy Code
    /lock:(none|checkin|checkout)
    • 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.

    NoteNote

    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.

    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

    Understand exit codes

    Version control commands return the following exit codes:

    Exit Code

    Definition

    0

    Success.

    1

    Partial success; this means at least something, or possibly everything, failed to succeed.

    2

    Unrecognized command.

    100

    Nothing succeeded.

    For example:

     Copy imageCopy Code
    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.