32

I'm using Perforce P4V, the graphical tool, to interface with my Perforce server here at work. I have a project I added to the depot and I accidentally deleted it from my workspace on my local computer, problem is when I use the Get Revision Action (the GUI equivalent of sync), the files don't get updated, i.e. I can see the files on the server that I want, but they won't sync correctly with my local PC. It's frustrating me that the files aren't getting pulled from the server. What I'm assuming should be happening is if files are altered in anyway on my local PC, I should be able to grab the revision from the server, which then pulls the data to my local PC and overwrites the changes locally on my PC, but that isn't happening. Is there something I'm missing?

kingrichard2005
  • 7,179
  • 21
  • 86
  • 118

7 Answers7

62

Perforce keeps track of the files that it thinks that you have on your local workstation. If you delete those files locally (and don't "tell" perforce about it), then Perforce will still think that you have those files. If you want to get them back, you need to "force sync" the files. In p4v, you can use the "Get Revision..." item and in the subsequent dialog, you can check the "force operation" checkbox to tell Perforce to give you all the files again regardless of whether Perforce thinks that you need them.

Just to complete the information, if you ever do want to remove the files locally, you can do so through p4v by choosing the "Remove from Workspace" item. Doing so will remove the files locally as well as tell perforce that you no longer have those files so that next time you sync, those files will be retrieved from the server.

Mark
  • 10,022
  • 2
  • 38
  • 41
  • 1
    Adding to the top answer - the way to do this through the command line interface is to do a `p4 sync -f ` on the file or path that you are trying to sync (as mentioned by @Greenish below). – Jacob Ritchie Apr 01 '16 at 00:35
  • 1
    Even with the force flag it often doesn't work - what does it for me is to revert the local new files, and then force sync – citizen conn Mar 10 '17 at 09:33
15

Like other people have mentioned, one solution is to do a "force sync" the entire depot which is basically overwriting everything from server into your local. The downside to this is that it could take a LONG time to finish if you are working on a big depot.

Another alternative is to compare your local workspace with the server, then only force sync the files that are missing from your workspace.

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

-sd option: Show only the names of unopened files that are missing from the client workspace, but present in the depot.

There are more options (sa/se/etc.) available if -sd is not what you need. see here.

credits for the command goes to this blog.

Zahra
  • 6,798
  • 9
  • 51
  • 76
  • For anyone living in the "real world" with the kind of giant projects that are typically stored in Perforce, this is the only realistic answer. Using an ordinary force sync on a checkout that contains 100s of gigs of files is going to force pull every file again, it's much more useful to fetch only missing files – Shukri Adams Oct 21 '22 at 13:42
11

They won't update because according to Perforce you still have the files on your local machine.

You need to use the "Get Revison..." option and enable the "Force Operation" option.

This will tell Perforce to refresh all the files even those it thinks you have the latest version of.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
11

"Get Revision" will update only files that are not opened (checked out) even when "Force Operation" is enabled. You should revert all files marked as checked out in that workspace, and then use "Get Revision" with "Force Operation"

Arthur H
  • 181
  • 3
2

I did as you suggested, but I kept getting the message that the files were still open for edit and cannot be deleted, when trying Remove from Workspace.

Also, Get Revision returned with a message that no files were updated.

What I ended up having to do was Revert the files, then do the Get Revision action, that solved the problem.

Zahra
  • 6,798
  • 9
  • 51
  • 76
kingrichard2005
  • 7,179
  • 21
  • 86
  • 118
  • 10
    Please don't use answers to comment. You have the rep, leave a comment(s). Have a look at [this discussion](http://meta.stackexchange.com/q/74194/4228). – raven Jan 27 '11 at 14:50
  • 2
    @raven - don't forget the OP can always comment on answers to their own questions anyway. – ChrisF Jan 27 '11 at 18:38
1

For people coming into this question, this worked for me on the mac command line ...

cd into your local perforce workspace - the base directory of the checked out files that you are working on.

p4 sync -f

-f is to force the sync.

This can also come in handy when you restore a mac from a time machine backup.

https://www.perforce.com/perforce/r12.1/manuals/cmdref/sync.html

ryan
  • 841
  • 8
  • 12
-2

Check out the file, change it a little bit and then revert. Perforce will replace the local file with the latest revision.