Locks or unlocks a file or folder to deny or restore the right of users to check out an item for edit into a different workspace or to check in pending changes to an item from a different workspace.
To use the lock command, you must have the Lock permission set to Allow. Having the Unlock other user's changes permission set to Allow is required to remove a lock held by another user if you do not have Write permission for that user's workspace. For more information, see Team Foundation Server Permissions.
tf lock itemspec /lock:(none|checkout|checkin) [/workspace:workspacename] [/server:servername] [/recursive]
Identifies the file or folder to lock or unlock. For more information about how Team Foundation parses itemspecs to determine which items are within scope, see Command-Line Options.
The user-provided value for the /workspace option.
The user-provided value for the /server option. Example: http://teamfoundation2:8080/.
Specifies a lock type or removes a lock from an item. For more information, see Understanding Lock Types.
Specifies the name of a different workspace in which to apply the lock. By default, the lock is applied in the workspace in which you are currently.
Specifies the URL of the Team Foundation version control server to work in. This option is required if the command is invoked from a directory that is not mapped to a workspace.
You can use the lock command to temporarily freeze the Team Foundation version control server version of an item so that you can check in a pending change without having to resolve any merge conflicts. If you want to permanently prevent access to an item in the Team Foundation version control server, you should use the Permission Command instead.
As a courtesy to your teammates, notify them when you apply a lock to an item, explain why you are doing this, and estimate when you plan to remove the lock, if you can.
For more information on how to find the tf command-line utility, see Tf Command-Line Utility Commands.
How to Lock an Item
You can lock an item using the lock command or by specifying a lock option during the commission of several other commands of the tf command-line utility that includes:
For add and branch, the lock is placed on the namespace where the new item will be created. Locks placed with rename apply both to the old and new namespaces. For more information, see How to: Lock and Unlock Folders or Files.
Team Foundation provides two types of locks: checkin and checkout.
A check-in lock is less restrictive than a check-out lock. When you apply a check-in lock, users can continue to make local changes to the item in other workspaces. The changes cannot be checked in until you explicitly remove the check-in lock from the workspace.
A check-out lock is more restrictive than a check-in lock. When you apply a check-out lock to a version-controlled file or folder, users can neither check out the file for edit nor check in pre-existing pending changes. You cannot acquire a check-out lock if there are currently any pending changes to an item.
For more information about when to apply a check-out lock and when to apply a check-in lock, see Understanding Lock Types.
How Locking Works
If you have a file checked out when you lock it, its status is modified to contain the new lock type. If the files are not checked out, a "lock" change is added to the set of pending workspace changes. Unlike the checkout command, lock does not automatically make a file editable.
Locks on folders are implicitly recursive. If you lock a folder, you do not have to lock the files it contains unless you want to apply the more restrictive check-out lock to a file in a folder that has a check-in lock.
Unlocking an Item
You can unlock a locked item using the none option. Additionally, Team Foundation unlocks an item automatically when you check in pending changes in the workspace.
You can determine which files are locked in the Team Foundation version control server and by whom the files were locked using the Status Command.
The following example prevents other users from checking out 314.cs.
c:\projects>tf lock /lock:checkout 314.cs
The following example prevents other users from checking in changes to 1256.cs but enables them to check it out in their workspaces.
c:\projects>tf lock /lock:checkin 1256.cs
The following example prevents other users from pending changes to any items in the src/ folder in the Team Foundation version control server.
c:\projects>tf lock /lock:checkout $/src
The following example unlocks and makes all files in the src/ Team Foundation version control server folder available for check-out and check-in by other users.
c:\projects>tf lock /lock:none src/