Using the tf Command-Line utility to recover from a “minor” catastrophe

We published the “Can I use the tf Command-Line utility against a DiscountASP.NET Team Foundation Server 2010 server?” Knowledge Base article and there’s been some questions regarding some extended use since there’s only an example of the “undo” command.

There are several tf commands that are available but I’ll just provide an example based on the most frequent question that I typically see in the support queue.

So, you’re working with a developer, Joe who wasn’t feeling very well and went home for the rest of the day with all of his belongings, including the laptop that he normally works on.

All that’s required are some minor changes to the Default.aspx file so you connect to your DiscountASP.NET Team Foundation Server, connect to the WebSite project, you get the latest files that are available and you notice:

Hmm, maybe I can just check this file out and it’ll let me do the work when:

Ok, this isn’t looking good because I must finish the work but how am I going to undo the lock and check-out since Joe took his laptop home?

Now is when the tf command comes in handy!

First, make sure that you have administrative privileges at the Team Project Collection level or at the Team Project level.

To get to the tf command, you can do any of the following and I prefer the first two methods (assuming you’re using Windows 7):

1. Click the Start Orb and search for Visual Studio Command Prompt (2010).
2. Click the Start Orb, access All Programs, then Microsoft Visual Studio 2010, then Visual Studio Tools and then open Visual Studio Command Prompt (2010).
3. As an alternative, you can open up a Command Prompt window and then change paths to C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE. If you’ve installed Visual Studio to a different path, you’ll need to access the correct folder.

Depending upon your workstation configuration, you may need elevated privileges so it may be best to run the Command Prompt as an administrator.

So the error message that we encountered actually provides us with all of the information that we’ll need to undo the lock. We have the path to the item, the user and the workspace name.

The command that you’ll run would look something like this:

C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE>tf undo /workspace:”Joe’s Workspace”;COLLECTION_dev01 collection:https://tfs01.discountasp.net/tfs/COLLECTION $/WebSite/Default.aspx

The results would be:

The operation completed successfully. Because you do not have Use permission on the workspace Joe’s Workspace;COLLECTION_dev01, you must perform a separate get operation in that workspace to update it with the changes that have been made on the server.

Success! Time to make the changes and call it a day but as you’re working, you delete the file and somehow manage to check-in the change. The day seems to be getting worse but this is also something that we can recover from.

Since the file is still available locally, you can undelete the file using a tf command as well. You’ll need to know what folder you’ve created a workspace mapping to and for this example, the workspace that I’m using is set to C:\WebSite. Here’s the command:

C:\Program Files\Microsoft Visual Studio 10.0\VC>tf undelete C:\WebSite\Default.aspx

C:\WebSite:
Default.aspx

Check-in the undelete operation and you’re back in business.

If you ever need to get a list of deleted items for a particular folder, you can use yet another tf command:

C:\Program Files\Microsoft Visual Studio 10.0\VC>tf dir $/WebSite /deleted /collection:https://tfs01.discountasp.net/tfs/COLLECTION

$/WebSite:
$Account
$BuildProcessTemplates
$Scripts
$Styles
About.aspx
About.aspx.vb
Default.aspx;X4
Default.aspx.vb
Global.asax
Site.master
Site.master.vb
Web.config

12 item(s)

The deleted file is denoted with the X4 which is the deletion identifier.

While I hope that you’ll avoid having a day like this, in the event that it does happen, you’ll know what to do.

There are several other commands that are available and if you have any questions, feel free to post in the TFS Forum for help.

3 thoughts on “Using the tf Command-Line utility to recover from a “minor” catastrophe

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.