SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
ASP.NET, VB.NET, Microsoft .NET Framework, Microsoft Visual Studio, Windows Forms, Controls and more Tutorials and Articles for Programmers


TFS Undo Checkout or Unlock Pending Changes on Another Developer's Workspace using Team Foundation Server TF Undo Command


If you are building your software applications using Visual Studio 2005 or VS2008, you are probably using Visual Studio Team System Team Foundation Source Control for controlling the source codes and code files within your project or solution.
Team Foundation Source Control is the successor of Microsoft Visual SourceSafe as a source control software required especially for software development teams.

We are using the Team Foundation Server (TFS) as our source control and I have faced the necessity to undo pending changes or tfs undo pending checkins on an other developers computer or workspace.
A few times, developers among the developer team has check-out the code files and forget to check in the source files.
I believe if you are using the Team Foundation Source Control as your source control software you have experienced similar needs for various reasons.
It is not so simple now to undo a pending checkin or unlock pending changes as easy as you did in MS VSS. We have to get help from the Team Foundation Source Control command line tool.
The TF Command Line Utilty has the solution required to interfere other developers' workspaces : Undo Command.

TF Command Line Utilty Undo Command :

The TF Undo command syntax :
tf undo [/workspace:workspacename[;workspaceowner]] [/server:servername] [/recursive] itemspec [/noprompt]
Code

You can run the Team Foundation Command Line Utility from the Visual Studio 2008 Command Prompt that can be found in the Visual Studio Tools menu group.

visual-studio-2008-command-prompt





Sample Code for Undo Pending Changes on Another Developer's Workspace using Team System TF Undo Command


In order to show you a sample how to unlock pending changes on a Team Foundation Server Source Control, I have followed the following steps :
I logged to my desktop computer and opened a team project using MS Visual Studio 2008. Note that the source control for the related solution is the Team Foundation Server.
I checked out an .aspx web page and edit the code-behind file by adding a few lines of codes.
Now I logged on to my laptop computer and connected to the same solution using the Team Explorer within the Microsoft Visual Studio 2008.
The Source Control Explorer is showing me that the EY.aspx file is checked out by yilmazer user (that is me) in some workspace also giving the workspace name.
When you try to check out the file from the Source Control Explorer you will also get a warning message about the check-in check-out status of the related files.

TFS-Team-Foundation-Server-Source-Control

Assume that a problem with the desktop computer caused the source files to be destroyed or corrupted on the desktop computer.
So the only solution is to undo pending changes on the related computer and continue with the server version.
Here is how we will manage this task using TFS Command Line Utility TF Undo command.

Let's remember the "TF Undo" syntax again here as much part as we will require:

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

Here the error or the warning information that is displayed on the Output screen when we tried to check-out the file will help us for the TF UNDO parameters :
workspacename is ISTW1029
We already know the server name since we are connected to the server via Team Explorer
itemspec is displayed in the output screen after the exception is thrown.

visual-studio-2008-command-prompt

Here is the tfs undo command we will execute on the Visual Studio 2008 Command Prompt tool in order to TFS undo checkout on the remote workspace.

tf undo /workspace:ISTW1029;yilmazer /server:istwcos01 /recursive $/Cosmos2008/Cosmos/OctopusWeb/Test/Eralper/EY.aspx
Code

TFS-Team-Foundation-Server-TF-Undo-Command

And the returned message from the TF Undo command is as follows :

C:\Program Files\Microsoft Visual Studio 9.0\VC>tf undo /workspace:ISTW1029;yilmazer /server:istwcos01 /recursive $/Cosmos2008/Cosmos/OctopusWeb/Test/Eralper/EY.aspx

The operation completed successfully. Because the workspace ISTW1029;yilmazer is not on this computer, you must perform a separate get operation in that workspace to update it with the changes that have been made on the server.
Code

After TFS undo checkout on another developers workspace, now you can check-out the related source files from the TFS (Team Foundation Server) Source Control and alter the source code as you wish in your workspace.



Visual Studio


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.