Perforce: Force update missing workspace files

Q: So I’ve accidentally deleted some random local files and I have no idea which ones. How do I get the files back when Perforce thinks they are still in my local workspace? I don’t want to force update all the files, that would take way too long.

A: Force update will do the trick, but it will take forever to pull the files down. With a little bit of digging in the documentation there is a way to diff your workspace against the Depot.

p4 diff -sd //Depot/path/... > UpdateList.txt p4 -x UpdateList.txt sync -f

As shown above the Diff command is used to write out all the files that it didn’t find in the local workspace to a file named UpdateList.txt. Writing out to a text file can be useful if you need to check which files are missing or if you need to copy the list for another means. The output file will contain all the files that are missing from your workspace and also include any files that were moved/renamed in pending change lists under the specified path. In the second line you can see that the force update uses the files listed in the updateList.txt to only get what is missing.

In the command used below as my friend Dennis Roche pointed out, it can also be written as a single line if you don’t need a file list before an update.

p4 diff -sd //Depot/path/… | p4 -x – sync -f

NB: If you have a pending changelist that contains moved/renamed files, force update will not effect/replace them.