102

As the resident TFS admin, on occasion I am asked to undo a checkout (usually a lock) that a user has on a certain file checked into source control.

How do you undo another user's checkout?

brett rogers
  • 6,501
  • 7
  • 33
  • 43

4 Answers4

153

There are at least 2 different ways to do this:

Command Line

There is a command-line utility called Tf.exe that comes with Team Explorer. Find the documentation here. It can be accessed by launching a Visual Studio Command Prompt window. The syntax of the command is:

tf undo [/workspace:workspacename[;workspaceowner]] 
[/server:servername] [/recursive] itemspec [/noprompt]

For one file

tf undo /workspace:workspacename;workspaceowner $/projectname/filename.cs

GUI

The second is via the GUI, but does not come standard - you have to install the TFS Power Tools. See here for details on how to use this method.

Keep in mind that with either method you will need the appropriate rights. The permissions are called "Undo other users' changes" and "Unlock other users' changes". These permissions can be viewed by:

  1. Right-clicking the desired project, folder, or file in Source Control Explorer
  2. Select Properties
  3. Select the Security tab
  4. Select the appropriate user or group in the Users and Groups section at the top
  5. View the "Permissions for [user/group]:" section at the bottom

Deleting the workspace

tf workspace /delete WorkspaceName;User
             /server:http://server:8080/tfs/MyTeamCollection 
Community
  • 1
  • 1
brett rogers
  • 6,501
  • 7
  • 33
  • 43
  • For me the command tf undo /workspace:mydesk *.sdf reports "No pending changes" but does not undo the check-out (lock) – dumbledad Oct 28 '12 at 16:04
  • I forgot the TFS server path befor my *.sdf itemspec, I'd assumed it would work it out from the current directory. The command line you give works for me now. – dumbledad Oct 28 '12 at 16:14
  • 1
    Make sure you use quotes around paths with spaces, otherwise you might get message like: "No pending changes were found for $/xxx" – PeterX Jan 14 '14 at 03:15
  • How do I find the workspace name? I see I can run: tf workspaces /owner:[other user] /server:[server], I get a list of four workspaces the user has, but how would I know which workspace it is for the file? – PeterX Jan 14 '14 at 03:21
  • 1
    PeterX, you can see the workspace by navigating to the file in Visual Studio's Solution Explorer, right click the locked file and select Properties, then in the Status tab you have info about the workspace and user that locked the file – Dante Jul 07 '14 at 09:26
  • The tf undo command listed for undoing changes in a single file is missing the /server parameter. And like others said, pay attention to spaces in your file path. – Dante Jul 07 '14 at 09:28
36

The easiest way I found is to use the free TFS Sidekick application. It has an option to view and undo other user's checkout.

p.campbell
  • 98,673
  • 67
  • 256
  • 322
Marek Karbarz
  • 28,956
  • 6
  • 53
  • 73
  • 5
    It is below "Status Sidekick". Search, select files, undo. – Wolf5 May 30 '14 at 11:28
  • 1
    If user has left the company then you have to know the Active Directory username (which is not always same as user's firstname and/or lastname). My company assigns numbered usernames so I had to look up the retired user before I could search for him in VS or in the Status TFS Sidekick. – Zephan Schroeder Nov 04 '14 at 22:16
  • 1
    This application is sadly no longer available; the original website linked in the answer is down. – TylerH Jan 02 '23 at 19:31
31

I just had this problem myself and found an easier way to clean up old workspaces.

  1. In Visual Studio, open Source Control Explorer.

  2. From the 'Workspace' drop-down select 'Workspaces...'

  3. A dialog will appear showing the workspaces on your current PC. Select 'Show remote workspaces'

  4. You will now also see workspaces from your previous PC (as long as they are from the same user account). Select the old workspace(s) and click 'Remove'. This should delete the old workspace from from TFS along with any persisting checkouts.

I'm sure Arne has found a solution but I hope this helps others who google the issue.

saeid mohammad hashem
  • 1,271
  • 1
  • 15
  • 19
  • 9
    This works well if you are the workspace owner, especially for cleaning up your current list of workspaces. Not so good for deleting other user's workspaces or checkout locks :-). – Zephan Schroeder Nov 04 '14 at 22:13
  • Agreed. This works well for deleting your own checkout locks from another PC. – Chris Oct 15 '16 at 16:42
  • 2
    Right, but the question is specific to unlock files that are checked out to a DIFFERENT user. – BrainSlugs83 Feb 08 '17 at 21:05
8

Select your file in TFS sidekick, then above the list, you have a "undo pending Change". Click on that and the change will be undone :) The icon is similar to the "Undo" icon in MS word Get TFS sidekicks from http://www.attrice.info/cm/tfs/index.htm

Maryam
  • 89
  • 1
  • 1