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 command:
p4 delete //depot/file.txt
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
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/...
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:
Locate the changelist in question.
Right-click on this changelist and select 'Back Out Submitted Changelist'.
When prompted, choose to create a new change or use the default pending changelist.
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.
Right-click on your chosen changelist and select "Rollback' from the menu.
Choose the folder to which you wish to roll back.
The next field will be pre-populated with the change you chose; ensure this is correct, and change if necessary.
Keep the pending change as 'new', or choose an existing, pending change (default or numbered).
Having chosen these various options, you can preview the action, and click 'Submit...'.
Undeleting a Particular Set of Files
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.
Locate the file in the Depot tab pane.
Context-click on the file and select "File History".
Right-click the last good version of the file (without the X on the icon) and choose "Get this Revision".
In the Depot pane, context-click on the file and select "Mark for Add", "OK" if prompted.
Locate this file in P4V, whether in the pending change, the depot or workspace tree view.
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:
Choose 'Get latest' from the file's context menu.
Mark the file for add.
Submit this change.
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.