Undo / Unlock for Others with Team Foundation Version Control

Published 09 July 06 03:19 PM | dmckinstry

One typical scenario is the need to have an administrator (development lead, etc.) release the locks that a team member has placed on a file in the version control system.  This frequently occurs when a user has to make modifications to a locked file, and the peron who locked the file isn't available to unlock it. Team Foundation Version Control does support this capability, but is isn't complete obvious.  Here are the details...

The first step is making sure that you have the appropriate permissions.  The permissions are managed using the Source Control Explorer.  Each folder and file can be set to allow users or groups specific permissions, including: Unlock other user's changes and Undo other user's changes.  A user that is granted these permissions can perform the unlock or undo as described below.  By default, only the Project Administrators and Team Foundation Server Administrator groups have these permissions.

To actually perform the unlock or undo, you have to use the TF command from a Visual Studio command prompt.  It is somewhat unfortunate that these capabilities aren't available from Team Explorer or Source Control Explorer, but this is hopefully an infrequent enough administrative task that it doesn't cause too many issues.

The specific commands for unlock and undo are as follows:

TF LOCK filespec /LOCK:NONE /WORKSPACE:workspace;lock_user
TF UNDO filespec /WORKSPACE:workspace;checkout_user

The important things to realize about these commands are as follows:

  • Filespec will most frequently be a path to a file or folder in Team Foundation Vesion Control (TFVC).  For example: "$/MyTeamProject/MyFolder/Foo.cs".  If you have embedded spaces in the path, make sure to use quotes around the filespec.
  • Filespec can can be a local file (e.g., "C:\MyTeamProject\MyFolder\Foo.cs") only if that local path is in the workspace holding the lock or having the file checked out.  That means that it will have to be on the workstation of the user holding the lock/checkout.  You shouldn't need the workspace switch in this case, but I haven't actually verified this personally.
  • If TF can't detemine the server, you're also need a server switch on the command line (e.g., "/server:mytfs").
  • You can add the "/recursive" switch to unlock or undo all changes for a specific user recursively under a folder in TFVC.
  • The workspace can be queried by looking at the properties of the item in Source Control Explorer and switching to the Status tab.  It can also be queried using the TF command line utility.
  • The lock_user and checkout_user refer to the login for the user holding the lock or checkout.  For example: "notion\dmckinstry".

The examples above would look like this if you wanted to unlock the file "Foo.cs" from my "DaveWorkspace" workspace:

TF LOCK C:\MyTeamProject\MyFolder\Foo.cs /LOCK:NONE
       /WORKSPACE:DaveWorkspace;notion\dmckinstry

In theory, this same basic approach can be used to check in changes made by other users, but the note above pertaining to being in that user's workspace on their workstation would defintely apply.

 

Filed under:

Comments

# Team System News said on July 10, 2006 09:32 AM:

Eric Lee on be careful of proxy settings when using the Team Foundation Server Object Model, KPI and...

# MrDave's (David Yack) Blog! said on August 13, 2006 09:14 PM:

After traveling most of June, and then some in July it’s been hard catching back up but almost...

# UNDO Not work?? said on September 14, 2006 10:23 PM:

tf undo $"/Learning Team/Test/website" /workspace:ws0103;Edward /recursive report The workspace WS0103;Edward is not on this computer. Run get (get all if edits were undone) on the computer hosting that workspace to update it with the changes that have been made on the server. how can i do, thanks

# Paul Litwin's Blog said on September 30, 2006 08:33 PM:

We had a problem recently where one of out developers (a summer intern) left with some files checked

# nitedev said on April 25, 2007 09:15 AM:

It can't unlock the file and display this message

=================================

TF14090: Cannot unlock {0}. It is not currently locked in your workspace.

=================================


Nitedev - did you give the workspace name and owner information for the file you are trying to unlock?  It looks like you are trying to unlock for a user that doesn't have it locked.  Usually that is a person trying to unlock on behalf of someone else but not actually specifying the other user's workspace and ownership.

-Dave

# Krzysztof Szepietowski said on September 20, 2007 11:40 AM:

nitedev, I also have the same problem, even if a tried unlock file wchich I locked before in my computer, did you resolve the problem

regrads

krzysztof szepietowski

# Tips and Tricks said on May 10, 2008 09:34 AM:

To unlock a file in Team Foundation Server you have to issue the following command at the Visual Studio Command Prompt: TF UNDO filename /WORKSPACE:workspace;checkout_user /SERVER:servername ...

Leave a Comment

(required) 
(required) 
(optional)
(required)