This blog is subject the DISCLAIMER below.

Sunday, January 09, 2011

How to force undo checkout? #TFS

Sometimes you'd pop into cases where you find yourself in a situation where you have to force undo pending code changes of someone else (say a colleague who is no more around, or even temporarily) or your own pending changes if say your machine (along with your workspace on it).

Well, there a Visual Studio tool for that.. That's tf command-line utility, which you can look for in your VS directory under Common7\IDE..

Using tf has lots and lots of uses, here's a really LONG list of them. Note: there's 3 sub-lists for VS2005, 2008, 2010. But for our tiny problem here, we mainly have to options, I'm using here the most straight forward ones:

Undoing pending changes for a specific file:

That will need mainly main parameters to start with: The name/path of the file checkout, User name (of the user who did the checkout), and the Workspace in which the checkout was done (usually your machine name if you didn't create an new workspace).

You could have an issue with the third one (workspace name), so you might have to check the Workspaces command for more details, but generally a small command like the one below will do just ok in most cases:

tf workspaces /owner:UserName

Knowing the above you can easily undo the pending changes as below, note: parameters are in squiggly braces like {these}:

tf undo {file path} /workspace:{workspace};{username} /server:{TFS name/IP}

Of course the "/server" part can be removed if you're on the same server running TFS. An example with some data will look like:

tf undo $/myProject/myFile.cs /workspace:mySpace;FCIH\shady /server:FCIH_TFS

Deleting the whole workspace:

The other option is to delete the whole workspace, which in turn delete any related checkouts. A simple command for that could be:

tf workspace /delete {workspace};{username} /server:{TFS name/IP}

which with some example parameters might look like:

tf workspace /delete Shady-PC;FCIH\shady /server:10.0.0.2

UPDATE:

After a comment by Meligy, I think I needed to add this: Most of the above needs you to be logged in as an account with TFS admin privileges, check the exact required permissions for Undo, Workspace and Workspaces commands.

If you're not logged in as the appropriate account, you can append {/login:username, [password]} to provide the authorized username and password.

Meligy, also, mentioned another tool called TFS Sidekicks that can do similar stuff.

6 comments:

Mohamed Meligy said...

Nice post :)

Just to mention, in some cases, if these are not your changes, you'll not have access to do that. I got into this specific case a couple months ago.

IF you are working with TFS and run into such issues, this tool also can be very helpful:
TFS Sidekicks
http://www.attrice.info/cm/tfs/

Shady M. Najib said...

@Meligy: Nop.. if you're logged in as an admin it will work (I've tried it on TFS 2008, 2010 and it worked for me)

Also, there's /login:username,[password] which you might want to add to use another user log-in.

Shady M. Najib said...

Updated!

Mohamed Meligy said...

Thanks for the update. In fact, in my case, I did not have admin permissions. I tried doing similar stuff (deleting workspace on the same machine because my workspace needs to be in the same location due to certain folder setup at that client), and had to contact the "TFS admin team" to do it after getting hopeless (this was how I found about this tool BTW).

Maybe just I'm slowly dragged where not always the developer is by default the admin of everything :S

Shady M. Najib said...

You don't need to have a full TFS admin role.. But yup, with TFS admins present, probably you don't have the slightest hint of these..

Speaking of your last note, it reminds me of hanselminutes' Transitions podcast :P

nikkisa889 said...

Good day! I just want to give an enormous thumbs up for the good information you've got here on this post. I will be coming again to your blog for extra soon. free online casino slots