2
votes

I have deleted a directory in a 3rd-party Perforce client. It should have used p4 delete, but I cannot be sure. It was not submitted.

Now:

  • I don't see the deleted directory in p4v.
  • p4 revert fails:

    p4 revert //depot/path/deleted-directory/...
    //depot/path/deleted-directory/... - file(s) not opened on this client.
    
  • I cannot force-sync deleted-directory to revert the deletion:

    p4 sync -f //depot/path/deleted-directory
    //depot/path/deleted-directory no such file(s).
    
    p4 sync -f //depot/path/deleted-directory/...
    //depot/path/deleted-directory/file1.txt#2 - deleted as /Users/me/depot/path/deleted-directory/file1.txt
    
  • I cannot reconcile them:

    p4 reconcile //depot/path/deleted-directory/...
    //depot/path/deleted-directory/... - no file(s) to reconcile.
    
  • p4 opened doesn't see them:

    p4 opened
    File(s) not opened on this client.
    

How do I get this deleted directory into a changelist or at least revert it?

I tried all suggestions from "I've deleted all the files in my directory. How can I get them back?" except for checking out a new workspace, which I will eventually do.

1

1 Answers

1
votes

Short answer:

p4 undo //depot/path/deleted-directory/...#head
p4 submit

That will undo the head revisions in that directory (i.e. the deletion) by creating new revisions that are copied from the prior ones.

Longer answer to explain why all the things you tried didn't work:

p4 opened and p4 revert both operate on files that are currently open. If you hadn't yet submitted, then revert would put the files back, but since this deletion was already submitted, there were no open files to revert.

When you force-synced you were just forcing a re-sync to the head revision, which is deleted (just like the files in your workspace), so no matter how hard you force the sync all you're going to get is a lot of nothing. If you had done:

p4 sync "//depot/path/deleted-directory/...#<head"

in order to sync to the revision prior to #head, that would have done the trick. Note that no -f flag is necessary. Once the files were synced to the correct revision, you would also be able to undo the delete by following that sync command with:

p4 add //depot/path/deleted-directory/...
p4 submit

Similarly, reconcile didn't do anything because the files are deleted at the head revision and deleted in your workspace, so there's nothing to reconcile. If you wanted to get really weird with it you could undo the delete via reconcile by using a combination of sync and flush to simulate the condition of having re-added new copies of the files:

p4 sync "//depot/path/deleted-directory/...#<head"
p4 flush //depot/path/deleted-directory/...
p4 reconcile //depot/path/deleted-directory/...

In addition to being unnecessarily complex, this reconcile-based solution will lose the information of which revision the re-added files came from (thanks to the p4 flush), so I would not recommend it. Go with undo and if you're on an old server version that doesn't support that do the normal sync/add thing.