I recently received a query, which in essence can be summarised as: “How can I create a list of deleted files and folders in Team Foundation Server (TFS) hat are safe to be deleted permanently”. The question is an interesting one and probably highlights some additional functionality which we hope to see in future releases. Analysing the query we need to complete two steps:
- Create a list of files and folders that have been deleted
- Determine which of these files and folders can be safely deleted
The first one sounds reasonable, however, the second immediately creates a shiver down my spine. deleting anything in a version control system makes me nervous and we should therefore create a backup immediately. In this case we will use a demo environment, so for once we can skip the backup as any damage inflicted by a delete operation will be superficial 🙂
Step 0 – Create the test environment
To start with we create a team project, in this case DeletionJourney, and add two simple console application projects HelloWorldDemo and HelloWorldDemoBad.
As we obviously want to investigate deleted files and folders, we delete the HelloWorldDemoBad project in the Source Control explorer. The pending change is “delete” and we can see the red cross in front of the folder, warning us of the imminent disappearance act.
We then check-in pending changes and voila, magic, the folder disappears … we are made to believe. In fact the files and folders are attributed with a deleted state, but are still hiding in the version control repository.
Step 1a – Create a list of files and folders that have been deleted (Option A)
The first option to see deleted files and folders we will investigate is within the integrated development environment. If you go to the menu and select Tools –> Options –> Source Control –> Visual Studio Team Foundation, you will notice the option to “Show deleted items in Source Control Explorer”. Check this option.
But there is more … Can we undelete in the Source Control Explorer?
Step 1b – Create a list of files and folders that have been deleted (Option B)
The other option is to roll up our sleeves and open the Visual Studio Command line. Run the tf del /? command to see the option to display all or parts of the version control server, taking note of the /deleted argument option.
If we run tf dir $\DeletionJourney /deleted /folder /recursive we are presented with all the folders in our project and an indicator next to our deleted items.
If we drop the /folder from the command, we are presented with files and folders, including the indicator of deleted items.
What is missing is additional information that shows information such as “when” was the file deleted and “by whom”. This is some of the additional functionality we mentioned upfront 🙂
Step 2 – Delete the relevant files and folders
So, how can we find the details such as the “when” and “by whom”? We go back to the Source Control Explorer. We then find the relevant history … in our case we can get the history at root level as it is a small project and we added check-in comments. In larger projects you may want to fine tune this history.
Once we know the relevant changeset, we can get the details and we are presented with the files and folders making up the changeset, when it was created and by whom.
At this stage we have answered the first question “Create a list of files and folders that have been deleted”.
What about the second “Determine which of these files and folders can be safely deleted”? Well, this is where I take a huge step back, because I like the fact that the artefacts are deleted, but still recoverable in the version control. The word “safely” in the question scares me a bit, because no deletion is ever save.
My two cents worth … From over 25 years experience, I know that whenever anything is deleted permanently, you will have someone storming into your cave within a short period of time looking for the deleted artefacts and from that point onwards none of the backups you find will ever work again. Ever heard of the mission critical systems for which none of the code can be found, of the 1/2” inch tapes that were stored the wrong way and are now useless, of the DVD backups that were made and securely stored, but for some strange reason cannot be found?
If you really have to delete the files and folders permanently, you can look at the command tf /delete /? … but before you drop the /? from the command make sure your hands are off the keyboard, you are literally sitting on your hands and you think about what you are about to do carefully.
Hope this brief excursion has highlighted the options and the dangers.