Delete or restore files and folders in TFVC
Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019
Visual Studio 2019 | Visual Studio 2022
You can delete and restore files and folders from Team Foundation Version Control (TFVC), from the workspace on your dev machine or on the server.
Prerequisites
Delete an item
Before you delete a file, look for a next to the file, which indicates pending edits in the file. If there are pending edits, view them by right-clicking the file and choosing Compare. Make sure that you don't need the edits. If you think you might need the edits in the future, consider checking in the file before you delete it.
Important
- If you delete a folder, the system pends delete actions for any folders and files that the folder contains.
- If you delete a file on which other files have dependencies, the system automatically pends delete actions for those files. For example, if you delete a form file, the code and resource files are also pended for deletion.
To delete an item
In Visual Studio, either in Solution Explorer or Source Control Explorer, browse to the folder or file that you want to delete.
Right click the item and choose Delete.
If you're deleting the file from Solution Explorer, the following warning message may appear: <filename> will be deleted permanently. Choose OK if you want to proceed with deleting the file.
When you're ready, check in your changes.
If you're not using TFVC, use Solution Explorer to delete items and files in your Visual Studio solution.
Recover or restore deleted items
If the deleted item was under version control before the delete, then you can recover the item. The deletion won't be implemented on the server until you check in the change.
Recover a deleted item by using Team Explorer
- Open the Pending Changes page in Team Explorer.
- Right-click the deleted items under Included Changes and choose Undo.
- In the Undo Pending Changes dialog box, select the item and then select Undo Changes.
Recover a deleted item by using Source Control Explorer
- In Source Control Explorer, browse to and right-click the file you deleted, and select Undo Pending Changes.
- In the Undo Pending Changes dialog box, select the item and then select Undo Changes.
Recover a deleted item by using Solution Explorer
Files not under version control that you deleted through Solution Explorer are moved to the Recycle Bin on your computer, where they can be restored. Once restored from the Recycle Bin, right-click your solution in Solution Explorer and select Add > Existing item to restore the file into your solution.
Restore a deleted item from the server
If you've already checked in the deletion of an item in TFVC, you can restore the deleted item from the server as long as no one on your team has destroyed it.
- From the Visual Studio menu bar, choose Tools > Options.
- In the Options dialog box, navigate to Source Control> Visual Studio Team Foundation Server.
- Select the Show deleted items in the Source Control Explorer, and then choose OK.
- In Source Control Explorer, browse to and right-click the file you want to restore, and select Undelete.
Restore an item deleted from your dev machine
You might need to restore an item you deleted outside Visual Studio, possibly by accident. The method you use to restore such an item depends on whether you're using a local or a server workspace. See Decide between using a local or a server workspace.
When you use a local workspace, Visual Studio detects and enables you to resolve changes you made outside the system.
- On the Pending Changes page in Team Explorer, under Excluded Changes, select Detected.
- In the Promote Candidate Changes dialog box, right-click the item, which has delete in the Change column, and select Restore this item.
- Select Promote.
If you accidentally delete an item outside Visual Studio and you're using a server workspace, when you try to open the item in Visual Studio you might see an error message such as: TF10187: Could not open document <filename>. The system cannot find the file specified. You can restore the item by getting it from the server.
- In Source Control Explorer, browse to the folder that contains the deleted items.
- Right-click the folder and choose Advanced > Get Specific Version.
- In the Get dialog box, select Overwrite all files even if the local version matches the specified version.
- Choose Get.
Tip
You can also use the tf get /force command.
Work from the command prompt
You can use the following tf command-line utility commands to delete, destroy, restore, and get files.
- The Delete command deletes a file from the server.
- The Destroy command permanently destroys an item.
- The Undelete command restores a file deleted from the server.
- The Undo command undoes pending changes.
- The Get command gets files from the server.