64

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?

Maxime Rouiller
  • 13,614
  • 9
  • 57
  • 107

12 Answers12

61

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

Atzoya
  • 1,377
  • 13
  • 31
Maxime Rouiller
  • 13,614
  • 9
  • 57
  • 107
  • How would I do this with different credentials? – Peet Brits Dec 22 '11 at 08:05
  • 3
    Let me rephrase. I use `tf lock /lock:none /login:... /workspace:... `, but it returns the error "must remain locked because its file type prevents multiple check-outs" – Peet Brits Dec 22 '11 at 08:26
  • 8
    Never mind, I resolved it with `tf undo` from Martin's answer. – Peet Brits Dec 22 '11 at 08:43
  • 1
    I had a similar issue but the recursive unlock using tf.exe that you suggested didn't work for me. (I didn't get any warnings. It just didn't unlock the files.) I installed sidekicks and was able to undo the locks using Status sidekick. I didn't want to delete the workspace or undo the checkouts because the developer was just out on vacation. – Mary Hamlin May 22 '12 at 14:12
  • 1
    Thx Max! The past you has helped me out once again! – Alexandre Brisebois Oct 29 '13 at 02:19
  • Maybe useful (duplicated?) http://stackoverflow.com/questions/1690520/how-to-undo-another-user-s-checkout-in-tfs – Kiquenet Oct 06 '14 at 09:53
36

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.

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
Martin Woodward
  • 11,770
  • 31
  • 45
  • 1
    +1. This worked whereas deleting the workspace didn't due to insufficient permissions and attempting to unlock the files gave an error. – djskinner Feb 27 '13 at 11:29
  • Problem is sidekick did NOT show me that another user had pending checkings. But neither did tf in the command line. It turned out the guy tried to checkin and it failed. And then just left it. So I added it to source again, and when I tried to checkin, some files checked in but other not. Really stupid situation. He had to do an undo on his machine to fix this problem, even though I deleted his TFS work space. – Piotr Kula Feb 04 '15 at 13:29
  • it worked, but be careful. if youre dealing with multiple workspaces of your own, you need to know you're gonna lose the changes on the deleted workspace perm. – Niklas Jun 28 '18 at 16:46
8

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.

AaronLS
  • 37,329
  • 20
  • 143
  • 202
7

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/

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
KeesDijk
  • 2,299
  • 1
  • 24
  • 37
1

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

  • List item

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

1

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.

DOK
  • 32,337
  • 7
  • 60
  • 92
0

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

tf workspace /delete /server:your_tfs_server workspace;username

Mrinmoy Das
  • 35
  • 1
  • 7
0

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...

DiningPhilanderer
  • 2,737
  • 3
  • 25
  • 29
0

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.

Tom Stickel
  • 19,633
  • 6
  • 111
  • 113
0

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 :)

Maciej Pulikowski
  • 2,457
  • 3
  • 15
  • 34
0

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
-3

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>>
  • Explain downvote please. I tried everything else that was suggested but I can confirm that this was the only thing that worked for me. In my case, the file was locked due to some mistakes during my employer’s move of TFS to another server. It was locked by my old username which had since been deleted. My new username was different and I could find no other way to link it back up. – Dennis T --Reinstate Monica-- Aug 20 '16 at 22:05
  • 3
    You should never touch the TFS database. You should use tools provided by Microsoft or even by third party like Atrice TFS Side kicks. That is why I down voted. – SoftwareCarpenter Sep 20 '16 at 14:56
  • I tried everything that was suggested online: TFS admin tools, deleted cache folder, used the workspaces dropdown, tf workspaces /remove:*, cleared credentials from Control Panel, IE, etc. I didn’t try Sidekicks, but after hours of trying to use other tools I judged it to be better to go straight to the source—this worked, and my TFS is still standing. Finally, reverting the change is a simple matter of replacing NULL with the old value. – Dennis T --Reinstate Monica-- Jun 29 '17 at 22:31
  • It's very easy using Atrice sidekicks. Simply locate file and hit the unlock button. Are you an admin or did you check permission on that file? Anyway if you got what you needed. – SoftwareCarpenter Jun 29 '17 at 22:35
  • I was given admin rights to troubleshoot this issue since my TFS admin could not figure it out. He had completed moving TFS to a new server a few days ago. The file was locked by my old user account on the old server. No way to reinstate the old server or account. Do you think Sidekicks would still have worked? I thought it wouldn’t. – Dennis T --Reinstate Monica-- Jun 29 '17 at 22:39
  • 1
    Yes, sidekicks let's you view all workspaces and also let's you delete them. It would delete the reference that is stored in TFS not the actual computer it was associated with. – SoftwareCarpenter Jun 29 '17 at 22:42