perforce: sync to an earlier revision

If you want to sync a specific version number (not changelist number) for a specific file. This worked for me:

p4 sync //your/depot/path/and/file.name#1

to verify you have the version you want, you can use the have cmd

p4 have //your/depot/path/and/file.name

I found the answer while writing my question. I have been trying:

p4 sync ...@x0 

where x0 is the changelist before the change containing the fix. But only a fraction of files was getting reverted. I found the issue that when we specify ... only the files in that folder and subfolder(s) get synced. So above command should be executed from the root of the workspace.


Say that you want to go back to revision 'n' from revison 'n+1' (rollback). You can take the following steps:

  1. p4 sync ...@n

    This will sync your files to the older version that you want

  2. p4 edit ...

    Open all the files for edit or do "p4 edit filename" to open only a particular file for editing.

  3. p4 sync ...@n+1

    Before submiting you need to sync files to the latest revision on the repository.

  4. p4 resolve -ay

    This will accept the changes that you have made, ie, revert all the changes done when you moved from revision 'n' to 'n-1'. So effectively, all your files have been rolled back to revision 'n' in your local repository.

  5. p4 submit ...

    Go ahead and submit the changes. This will roll back all main repository to revision 'n'. Effectively the revisions 'n' and 'n+2'(current) will be identical.

  6. p4 diff2 -q repository@n repository@n+2

    This is just to verify if have rolled back the files. This should show that you have no differing files in the two revisions.