Do a google search for “how to check-in another user’s changes in TFS” and you will find a couple of pages of MSDN documentation and a whole lot of forum articles questioning how to do this. Unfortunately, there is no UI option to do this, so you must resort to the command-line.
Here’s the command syntax for the UNDO command (see MSDN for more on this):
tf undo [/workspace:workspacename[;workspaceowner]] [/recursive] itemspec [/noprompt] [/login:username,[password]] [/collection:TeamProjectCollectionUrl]
Too often, the TFS commands don’t come with any explicit examples, so you’re left guessing about how to implement the syntax described above. In this article, I show you how to use the command detailed above.
Changes You Can’t Access Anymore
There are two scenarios where you can’t access the changes anymore to Undo them normally:
- Someone else’s changes (perhaps they have moved on)
- Your changes on a different computer (perhaps your old laptop)
In either case, you can tell from Source Control Explorer in Visual Studio who the user is that holds the lock, but you can’t tell the Workspace they used. So, first, we will need to figure out which Workspace contains the changes.
Identify the Workspace that Contains the Change
To identify the Workspace, we will use the TF STATUS command. In this command, you can specify the Folder or File(s) with the pending changes using your local Workspace, and you can specify the user who holds the lock on the files. TF STATUS then tells you the details of the pending change(s), including the Workspace that contains the change/lock. Here is an example using the LocalFolder\* format for itemspec to find all the files Joe Wren has a lock on:
tf status "C:\_myTFS\SCMFolders\MyVSSolutionFolder1\MyVSProjectFolder1\*" /recursive /format:detailed /user:DOMAIN\Joe.Wren
When you execute this command from the VS2013 Command Line (Start | Programs | Visual Studio 2013 | Visual Studio Tools | Developer Command Prompt for VS2013). You get a listing of all the files Joe Wren holds changes for, and it looks like this:
$/SCMFolders/MyVSSolutionFolder1/MyVSProjectFol der1/Package1.dtsx;C1276 User : Wren, Joe Date : Monday, May 02, 2016 2:55:53 PM Lock : none Change : edit Workspace : JWs-Laptop Local item : [JWs-Laptop] C:\_myTFS\SCMFolders\MyVSSolutionFolde r1\MyVSProjectFolder1\Package1.dtsx File type : Windows-1252 $/SCMFolders/MyVSSolutionFolder1/MyVSProjectFol der1/MyProject.dtproj;C1276 User : Wren, Joe Date : Monday, May 02, 2016 2:56:41 PM Lock : none Change : edit Workspace : JWs-Laptop Local item : [JWs-Laptop] C:\_myTFS\SCMFolders\MyVSSolutionFolde r1\MyVSProjectFolder1\MyProject.dtproj File type : utf-8 $/SCMFolders/MyVSSolutionFolder1/MyVSProjectFol der1/MyProject.dtproj.vspscc;C1269 User : Wren, Joe Date : Monday, May 02, 2016 2:56:41 PM Lock : none Change : edit Workspace : JWs-Laptop Local item : [JWs-Laptop] C:\_myTFS\SCMFolders\MyVSSolutionFolde r1\MyVSProjectFolder1\MyProject.dtproj.vspscc File type : utf-8 3 change(s)
Notice the Workspace: JWs-Laptop line. That's the info we need.
Now Undo the Changes to that Workspace
Now that we know the Workspace (JWs-Laptop), we can undo the changes to that workspace by running the TF UNDO command (see syntax above), specifying the TFS Source Control Path for itemspec, the Workspace name and user, and the TFS Collection URL, like so:
tf undo "$/SCMFolders/MyVSSolutionFolder1/MyVSProjectFolder1/" /workspace:JWs-Laptop;DOMAIN\Joe.Wren /recursive /collection:"http://TFS-Server:8080/tfs/My%20Collection"
And that’s it. Using these two steps you can undo any changes in TFS.*
*Note: As long as you have the Undo Others Changes permission (which you get by being a TFS Admin or a Project Admin.