perforceperforce-client-specperforce-helix-core

Best way to sync latest files to pending changelist with outdated files using p4 cli


I have a pending changelist which contains outdated files. In order to get the latest changes, I follow these steps:

p4 shelve -c <changelist-number>

I revert all the files in this pending changelist.

I run the p4 sync command to get the latest changes

I unshelve the changelist to this same pending changelist

p4 unshelve -s <shelved-CL-number> -c <target-CL-number>

However, when I do the unshelve all the latest changes for the files in this CL disappear and it is back to how it was before I synced the changes.

What is the best way to do achieve this?


Solution

  • Perforce handles this automatically. Just do:

    p4 sync
    

    exactly like you normally would. The p4 sync won't clobber your pending changes; instead you'll see a message like must resolve FILE#REV for those files. Refer to the p4 sync documentation:

    to protect the person working in the local workspace from accidentally losing work, any files that are open in the local workspace when you run p4 sync need to be [...] resolved using the p4 resolve command before submitting.

    Now do:

    p4 resolve
    

    This will go through all those files where you got the must resolve FILE#REV message, and merge the newer changes from FILE#REV into your workspace file.

    You can shelve beforehand to make sure you have a backup of your workspace files (just in case something is messed up during the resolve, you can use the shelf to restore everything to its earlier state), but I generally don't bother with that unless I'm dealing with a lot of complex changes where the merge is likely to be difficult.