Removing Another User's Lock in TFS

One of the joys of distributed development teams is unexpected locks. In this particular case, the file was locked by a very distributed developer. And I needed to get it unlocked, as the lock was preventing a build from running. Oh, and I was using as the source control repository.

Step 1 – Determine the workspace

In order to perform an unlock/undo, you need to know the workspace and user involved. To find out the workspace for a user, there is a workspaces option for the tf command line prompt. So open up the Visual Studio Command Line window and navigate to your local mapped directory for the project. This navigation is important, as it allows you to minimize some of the command line options that we will be using.

Once you’re in the directory, execute the following command:

tf workspaces /owner;domain\userid

In this case (since we’re using, the domain\userid is actually the Live ID for the user that currently holds the lock. The output from this command includes the name of the workspace in question.

Step 2 – Undo pending changes (thus releasing the lock)

Another tf command is required for this step. In the same command line window, execute the following command:

tf undo itemspec /workspace:workspace;domain\userid

In this case, the itemspec is the path to the locked item (for example $/MyProject/Directory/fileName.txt), the workspace is the name of the workspace identified in step 2 and domain\userid is the login id (or Live ID in our case) of the person who owns the workspace (and who has the item checked out).

And voila. The lock is undone and I’m now free to wreck havoc…er…check in my code.

Pingbacks and trackbacks (2)+