Επεξεργασία

Κοινή χρήση μέσω


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

See Default TFVC permissions.

Delete an item

Before you delete a file, look for a check mark icon 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

  1. In Visual Studio, either in Solution Explorer or Source Control Explorer, browse to the folder or file that you want to delete.

  2. Right click the item and choose Delete.

  3. 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.

  4. 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

  1. Open the Pending Changes page in Team Explorer.
  2. Right-click the deleted items under Included Changes and choose Undo.
  3. In the Undo Pending Changes dialog box, select the item and then select Undo Changes.

Recover a deleted item by using Source Control Explorer

  1. In Source Control Explorer, browse to and right-click the file you deleted, and select Undo Pending Changes.
  2. 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.

  1. From the Visual Studio menu bar, choose Tools > Options.
  2. In the Options dialog box, navigate to Source Control> Visual Studio Team Foundation Server.
  3. Select the Show deleted items in the Source Control Explorer, and then choose OK.
  4. 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.

  1. On the Pending Changes page in Team Explorer, under Excluded Changes, select Detected.
  2. In the Promote Candidate Changes dialog box, right-click the item, which has delete in the Change column, and select Restore this item.
  3. 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.

  1. In Source Control Explorer, browse to the folder that contains the deleted items.
  2. Right-click the folder and choose Advanced > Get Specific Version.
  3. In the Get dialog box, select Overwrite all files even if the local version matches the specified version.
  4. 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.