Locking Version-Controlled Items to Prevent Changes
You can use the Lock command to temporarily prevent changes to a particular file or folder in the version-control server. This command can be helpful if you want to change an item in your workspace and then check it in without being forced to resolve any merge conflicts. Only one user at a time may hold a lock on a particular file or folder. If you want to prevent access to an item in a persistent way, you should use the Permission command instead.
Important
You can modify permissions only by using Team Explorer in Visual Studio. You cannot modify permissions by using the Team Foundation Server plug-in for Eclipse or the Cross-platform Command-Line Client for Team Foundation Server.
In this topic
Understanding Locks
Lock Folders or Files
Unlock Folders or Files
Required Permissions
To perform these procedures, your Lock permission must be set to Allow. For more information, see the following topic on the Microsoft website: Team Foundation Server Permissions.
Understanding Locks
You can specify two types of locks for version-controlled items:
Check-in lock - A check-in lock is less restrictive than a check-out lock. If you apply a check-in lock, users can continue to make local changes to the item in other workspaces. However, those changes cannot be checked in until you remove the lock or check in your changes.
Check-out lock - A check-out lock, which is more restrictive than a check-in lock, prevents users from checking out and making changes to the locked item in their workspaces. You cannot apply a check-out lock to an item for which any pending changes exist in any workspace other than your own. Therefore, a check-in or check-out lock guarantees that the holder of a lock in the workspace where it is locked will be able to check in changes first.
How locking works
If a file is checked out when you lock it, its check-out record is modified to contain the new lock type. If the file is not checked out, a "lock" change is added to the set of pending workspace changes. Unlike the Checkout command, the Lock command does not automatically make a file editable.
If you check out a file that is of a type that is treated as binary, Visual Studio Team Foundation Server might automatically lock it because binary files cannot be merged.
Team Foundation Server unlocks an item automatically when you check in pending changes in the workspace in which the item is locked. Locks are also released if you use the Undo command to delete pending changes.
Locks on folders are implicitly recursive. If you lock a folder, you do not have to lock the files that 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.
Only one user at a time may hold a lock on a particular file or folder. You can use the Status command to learn which files are locked in the server for Team Foundation version control and by whom they were locked.
A lock may be added either as its own operation or as part of multiple other operations, which include rename, checkout, delete, undelete, merge, branch, and add to version control. When you lock an item as part of an add to version control or branch operation, Team Foundation Server adds the lock on the server path where the item will be created. This function prevents another user from adding or branching a file to the same location. When you lock an item by using the Rename command, both old and new server paths are locked.
Unlocking an item
You can unlock an item explicitly by using the Unlock command or implicitly when you check the item in. When you check in pending changes to a locked item, Team Foundation Server removes any locks.
Note
By default, only administrators can be granted the UnlockOther permission. If you have the UnlockOther permission, you can remove a lock from an item in the workspace of another user by using the Lock command.
Lock Folders or Files
To lock a file or folder from Project Explorer or Package Explorer
Right-click the file or folder that you want to lock, point to Team, and then click Lock.
The Lock Files dialog box appears.
In the Lock Files dialog box, verify that the check box that corresponds to the file or folder that you want to lock is selected.
Perform one of the following tasks:
Click Check In – Allow other users to check out but prevent them from checking in.
Click Check Out – Prevent other users from checking out or checking in.
For more information about lock types, see Understanding Locks.
Click OK to lock the folder or file.
To lock a file or folder from Source Control Explorer
Open Source Control Explorer.
For more information, see Open Source Control Explorer.
In Source Control Explorer, right-click the folder or file to which you want to apply a lock, and then click Lock.
The Lock Files dialog box appears.
In the Lock Files dialog box, verify that the check box that corresponds to the file or folder that you want to lock is selected.
Perform one of the following tasks:
Click Check In – Allow other users to check out but prevent them from checking in.
Click Check Out – Prevent other users from checking out or checking in.
For more information about lock types, see Understanding Locks.
Click OK to lock the folder or file.
A lock change is added to the list of pending changes for the folder or file. If that folder or file appears in Project Explorer or Package Explorer, the icon indicates that the item is locked.
To lock a file or folder at a command prompt
At a command prompt, change directories to the folder that contains the files or folders that you want to lock.
Type tf lock /lock:LockType ItemSpec and then press ENTER. Replace LockType with checkin or checkout. Replace ItemSpec with the file or folder that you want to lock.
For the full syntax of the Lock command, see the following topic on the Microsoft website: Lock Command (Team Foundation Version Control).
Unlock Folders or Files
To unlock a file or folder from Project Explorer or Package Explorer
- Right-click the file or folder that you want to unlock, point to Team, and then click Unlock.
To unlock a file or folder from Source Control Explorer
Open Source Control Explorer.
For more information, see Open Source Control Explorer.
In Source Control Explorer, right-click the folder or file from which you want to remove a lock, and then click Unlock.
A lock change is removed from the list of pending changes for the folder or file. If that folder or file appears in Project Explorer or Package Explorer, the icon indicates that the item is not locked.
To unlock a file or folder at a command prompt
Open a command prompt, and change directories to the files or folders that you want to unlock.
Type tf lock /lock:none ItemSpec and then press ENTER. Replace ItemSpec with the file or folder that you want to unlock.
For the full syntax of the Lock command, see the following topic on the Microsoft website: Lock Command (Team Foundation Version Control).
See Also
Other Resources
Using Version Control (Team Explorer Everywhere)
Using Source Control Explorer (Team Explorer Everywhere)
Working with Team Foundation Server Workspaces (Team Explorer Everywhere)