What do you do if the file in TFS is locked by someone else?

For the following operation, you will need to be either a project administrator for the project you want to undo the check-in on or a Team Foundation Administrator if you want to do this across all projects.

If you still have the username of the person, you can simply do something like this:

  • Open up Visual Studio command prompt (Start -> Programs -> Microsoft Visual Studio 200X -> Visual Studio Tools -> Visual Studio 200X Command Prompt)
  • Run the following command:

tf lock /lock:none /workspace:WorkspaceName;USERNAME /recursive $/

To get the list of workspaces for a user, just run the following command from the same prompt:

tf workspaces /owner:username

For more commands, check tf /?


If the developer has left the organization, then the best thing to do is to delete their workspaces. This will unlock the files for you but also free up some resources on the server.

See the following blog post I did on the topic when it happened to me a few years ago.

http://www.woodwardweb.com/vsts/unlocking_files.html

You can either delete the workspace using the command line (tf.exe) or you can use the excellent TFS Sidekicks from Attrice.


This was the only way I resolved this, which involved deleting the user's workspace.

If the error message says "The item $/... is locked for check-out by someUser:1 in workspace someMachine123." then I use the command:

tf workspace /delete /server:http://machinename:8080/tfs/DefaultCollection someMachine123;someUser:1

There is just a single space between the collection URL and someMachine123;someUser:1.

Note that I payed attention to the fact that the error message mentioned the user as someUser:1, so I mimicked that in the command. It was not enough to just run the command with someUser only. I'm not sure what the :1 is all about but point being, mimick the error message.

Note the server has to be the fully qualified collection path, which you can find by going to Team Foundation Server Administration Console->Application Tier->Team Project Collections, the bottom pane will show a URL for the collection that is selected in the upper pane.

I also had a problem because I accidentally tried to use plural workspaces instead of just workspace because there is a similar command that is plural.