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

Version ControlCommand LineTfsAdministration

Version Control Problem Overview


Someone left the organisation but before leaving, he locked all the files for an unknown reason.

How do you unlock them all so that the other developers can work?

Version Control Solutions


Solution 1 - Version Control

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 /?

Solution 2 - Version Control

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.

Solution 3 - Version Control

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.

Solution 4 - Version Control

first you need to have the right to do this. If you have that the easiest is to use TFS sidekicks from attrice http://www.attrice.info/cm/tfs/

Solution 5 - Version Control

Here's an explanation of using TFS permissions.

> Having the "Unlock other user's changes" > permission set to Allow is required to > remove a lock held by another user.

Solution 6 - Version Control

I needed to add /collection:collectionURL otherwise the workspace could not be found:

  • List item

tf loc /lock:none /workspace:WorkspaceName;UserName /collection:collectionURL

Solution 7 - Version Control

Have a system administrator reset that users password, log on as that user, unlock all files...

I would think this is the solution to almost all 'someone who is no longer at this organization' questions...

Solution 8 - Version Control

It is better to delete the workspace of that user from the server. example

tf workspace /delete /server:your_tfs_server workspace;username

Solution 9 - Version Control

Sometimes this is masking an different problem with a completely different application is locked by another user, but you cannot even create a New Folder for the new project you wish to merge into ( target won't allow the creation and incorrectly stating that someone has a file locked in their name) but then you dig deeper and another project is the culprit.

So a completely different project can be the problem with it having files locked by someone else.

Solution 10 - Version Control

Method that worked for me, my account has administrator permission on TFS and project :

In Visual studio 2015:

  1. Go to Team Explorer
  2. Click right on your solution and choose Open in source control exporer
  3. On left side click right on your solution
  4. Choose Advanced
  5. Choose Lock...
  6. On left side click right on your solution
  7. Choose Advanced
  8. Choose Unlock (Now you can choose unlock)

Right now, every dev can easily commit his changes :)

Solution 11 - Version Control

by using TFS permissions, Open up Visual Studio command prompt,Run the following command:

tf undo /workspace:workspaceName;DomainName\UserName  $/file path in your solution

Solution 12 - Version Control

Use this solution as the very last resort.

I’m using TFS 2012. I went to the TFS database and ran the following queries. And it worked! Of course be very careful when messing with the database, take backups, etc.

The database is called Tfs_<<your_TFS_collection_name>>. Ignore the Tfs_Configuration MSSQL database. I'm not sure but if you don't have a Tfs_<<your_TFS_collection_name>> database, settings might be in the Tfs_DefaultCollection database. Locks are stored in tbl_PendingChange.LockStatus.

/*Find correct row*/
SELECT LockStatus, PendingChangeId, *
FROM tbl_PendingChange
WHERE TargetServerItem like '%<<fileName>>%'

/*Set lock status to NULL (mine was set to 2 initially)*/
UPDATE tbl_PendingChange SET LockStatus = NULL WHERE
TargetServerItem like '%<fileName>>%'
AND PendingChangeId = <<PendingChangeId from above>>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMaxime RouillerView Question on Stackoverflow
Solution 1 - Version ControlMaxime RouillerView Answer on Stackoverflow
Solution 2 - Version ControlMartin WoodwardView Answer on Stackoverflow
Solution 3 - Version ControlAaronLSView Answer on Stackoverflow
Solution 4 - Version ControlKeesDijkView Answer on Stackoverflow
Solution 5 - Version ControlDOKView Answer on Stackoverflow
Solution 6 - Version Controluser1977234View Answer on Stackoverflow
Solution 7 - Version ControlDiningPhilandererView Answer on Stackoverflow
Solution 8 - Version ControlMrinmoy DasView Answer on Stackoverflow
Solution 9 - Version ControlTom StickelView Answer on Stackoverflow
Solution 10 - Version ControlMaciej PulikowskiView Answer on Stackoverflow
Solution 11 - Version Controlaseman arabsorkhiView Answer on Stackoverflow
Solution 12 - Version ControlDennis T --Reinstate Monica--View Answer on Stackoverflow