|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
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.
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.
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.
Specifies the name of the workspace to work in.
Specifies the URL of the Team Foundation source 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 source 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 source control server, you should use theinstead.
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.
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.
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 source-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.
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 source control server and by whom the files were locked using the.
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 source control server.
c:\projects>tf lock /lock:checkout $/src
The following example unlocks and makes all files in the src/ Team Foundation source control server folder available for check-out and check-in by other users.
c:\projects>tf lock /lock:none src/