Perforce Public Knowledge Base - Recovering Deleted Files
Perforce Software logo
Reset Search
 

 

Article

Recovering Deleted Files

« Go Back

Information

 
Problem

How do I get deleted files back?

Solution

The answer depends on the way in which the file has been deleted.

File deleted in workspace

If you have deleted the file in your workspace using OS commands (del, rm, or similar), but Perforce thinks you still have that file revision, you have two options:

  • Use the undelete options in your OS, such as retrieving the file from the 'Trash' folder (not covered here);
  • Get Perforce to re-deliver the file by using a forced-sync.

A normal 'sync' of this now-deleted file revision would not work as Perforce believes you have the file already. However, the following command would force it to redeliver the file revision the server believes you 'have':

p4 sync -f //depot/file.ext#have

As this forced-sync redelivers the file revision from the depot, any alterations you have made to that file prior to deleting it would be lost.

If the file has been opened in the workspace (but then mistakenly deleted) you would need to revert this action before forced-sync would work.

Opened for delete

If you have marked a file for delete but not yet submitted this change, you can simply revert this file to undo the action. For example, you can undo this following command

p4 delete //depot/file.txt

by running

p4 revert //depot/file.txt

In P4V, locate the pending change containing this 'delete', right-click on the file itself and choose 'Revert' from the context menu.

A deleted revision that has been submitted to the depot

If you have marked a file for delete and submitted this change, you must re-add the revision of the file prior to the 'delete'.

At the command-line

To restore a file that was deleted in the depot, p4 sync the last "live" revision of the file, run p4 add to mark it for add, then p4 submit this change.

For example, if foo.c was deleted at revision 26, you restore it with:

p4 sync foo.c#25
p4 add foo.c
p4 submit

Alternatively, if you accidentally deleted all the files in //depot/main/src depot path by submitting changelist 300, you can restore them with:

p4 sync //depot/main/src/...@299
p4 add //depot/main/src/...
p4 submit

In either of these situations, please do check which files are included in the change you are submitting in either case; it is possible it may contain other files not yet ready for submit - especially if you are working with the default pending changelist.

Using the Perforce Visual Client, P4V

If you want to undo your entire last changelist, first open the Submitted Changelists pane, either from P4V's View menu or from the button with the blue circle/triangle icon. Then, you would:

  1. Locate the changelist in question;
  2. Right-click on this changelist and select 'Back Out Submitted Changelist';
  3. When prompted, choose to create a new change or use the default pending changelist;
  4. Submit this change to undo the actions in this submitted change.

To bring an entire depot path back to an earlier time, again start by opening the Submitted Changelists.

  1. Right-click on your chosen changelist and select "Rollback' from the menu;
  2. Choose the folder to which you wish to roll back.
  3. The next field will be pre-populated with the change you chose; ensure this is correct, and change if necessary;
  4. Keep the pending change as 'new', or choose an existing, pending change (default or numbered);
  5. Having chosen these various options, you can preview the action, and click 'Submit...'.

Undeleting a particular set of files.

  1. Ensure that the deleted files are shown in the Depot View pane;
    • go to the View or Search menu
    • select the Filter Depot menu and click on Show Deleted Depot Files
  2. Locate the file in the Depot tab pane.
  3. Context-click on the file and select "File History".
  4. Right-click the last good version of the file (without the X on the icon) and choose "Get this Revision".
  5. In the Depot pane, context-click on the file and select "Mark for Add", "OK" if prompted.
  6. Locate this file in P4V, whether in the pending change, the depot or workspace tree view;
  7. Right-click on the file and choose 'submit'

You may see the warning message, "Deleted: Edits to the file cannot be submitted without re-adding the file". This means that you have the file opened-for-edit, but someone has deleted this file before you have submitted your changes. To submit your file, you should:

  • Choose 'Get latest' from the file's context menu;
  • Mark the file for add;
  • Submit this change.

 

Obliterated files

Undoing the 'obliterate' of a file or file revision is a non-trivial task, requiring access to archive files, journals and backups at least. Contact your Perforce administrator for assistance.

Identifying the file revisions to be undeleted

If you cannot easily identify the file revisions you wish to undelete but DO know the approximate date, commands like 'p4 changes -u username //...@timestamp,timestamp' can help you. Replace 'username' with the user who submitted the change, and add an appropriate timestamp. Running 'p4 filelog' for a given file will allow you to see which file revision(s) have been deleted.

In P4V, look for changelists containing the deleted files in the 'Submitted Changelists' pane filtering by your username, or use the 'History' tab for a given depot path to see all changes affecting those files.

If you have any questions or would like additional guidance, please contact Technical Support.

Related Links

Feedback

 

Was this article helpful?


   

Feedback

Please tell us how we can make this article more useful.

Characters Remaining: 255