15

I deleted a file from Perforce in the last month. Is there a way to retrieve it from P4?

If so, what command can I use?

Note: I'm not the admin for p4. And I don't want the file back in P4 but I just want it in my local workspace.

Also, I don't know the exact timeframe when I deleted it in last month...What command can I run?

I'm running P4 on windows. I'll appreciate if someone can provide equivalent command for windows

Thanks!

Mike
  • 7,606
  • 25
  • 65
  • 82

3 Answers3

14

When you delete a file in Perforce, it creates a "deleted" revision, but the archive file is still there.

In the Perforce P4V GUI in the depot veiw, there is a filter symbol on top of the explore pane Yellow Flag.

Click on this and select "Show Deleted Depot Files".

Find the file you want to restore and right-click on it. Select "Rollback..." and revert it to the previous revision of that file (before it was deleted.)

By default it will create a new changelist, be sure to select the one you want if you already have one.

On the command line: p4 sync //depot/folder/subfolder/filename@changelist

PolyMesh
  • 2,228
  • 2
  • 20
  • 23
bluecap
  • 151
  • 1
  • 3
9

You can use either the command line or the GUI, from the command line p4 sync -f forces the files to be resynchronized. For more information see the Perforce Knowledge Base.

Gray
  • 115,027
  • 24
  • 293
  • 354
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
  • 1
    I looked at this article earlier but it recovers & checkin the file back into P4. I just want the deleted file in my workspace & not in P4. How can I do that? Also, I don't know the exact timeframe when I deleted it in last month...What command can I run? – Mike Jan 11 '12 at 19:55
  • If you don't want it re-added, just sync to it and don't add it back, ie. just stop after the "p4 sync" command in the guide. – Joachim Isaksson Jan 11 '12 at 20:01
  • I tried p4 sync but its giving me error: Client 'my-machine' unknown - use 'client' command to create it. – Mike Jan 11 '12 at 20:08
  • Preferably you should do it on a developer machine or a machine that has Perforce workspaces set up already. p4 client isn't the easiest command to guide someone through, at least for me :) http://www.perforce.com/perforce/doc.current/manuals/cmdref/client.html – Joachim Isaksson Jan 11 '12 at 20:10
  • 1
    'p4 print' the previous revision, and re-direct the output. – Bryan Pendleton Jan 12 '12 at 14:25
5

If you haven't committed the change list of deleted files to the repository, right click on the folder containing the deleted files in p4v and choose Get Revision. Be sure to check Force Operation and then Click Get Revision. Then the deleted files will be restored from p4 server.

ref: https://forums.perforce.com/index.php?/topic/1479-how-to-restore-files-deleted-in-p4c-workspace/#entry4726

zwcloud
  • 4,546
  • 3
  • 40
  • 69