Can I safely edit a renamed file in perforce

I have done this before in one go, but depending on your build process, I recommend against it. What I generally do is this:

  1. Move the file.
  2. If the move needs a change in order to compile, open it for edit and make those changes.
  3. Submit the changes, telling perforce to reopen the files for editing.
  4. Make the changes for path, etc., that don't cause compile errors but should be updated.
  5. Submit those changes with an appropriate description.

If you want to, however, you could just do all your changes in step (2) above. Perforce might change the flag for the new file from integrate to add, but it still remembers the source path for the file.

Edit: Better method

I realized that I often use a different method, but the idea of "moving" the file distracted me. So, I would recommend these steps instead:

  1. Integrate the file into the new path/name, leaving the previous file there. I am assuming that this won't break your build process.
  2. Submit the new file, checking it out again for edit after submission.
  3. Make the required changes to the new file, and to the project so that you are using the new file.
  4. Submit the edits for the new file.
  5. [Optional] You might need to check through branch specs to see if you need to map the old file into the new one in any branches.
  6. Create a changelist for deleting the old file, and submit it sometime later.

This method allows the edits to be cleanly separated from the rename/move, while never leaving the project in a state that won't compile.

Also, why wait for step 6? Sometimes, especially on bigger projects, you might want to move a file that another person is editing. Perforce will helpfully tell you this. By waiting to delete the file, you allow your coworker(s) to finish the edits and submit without needing to move their work manually. After the edits are submitted, they can be integrated into the new file, and then the old one can be safely deleted.


Submit the move change and then reopen for edit (you could use the reopen option too). This is much more readable to the user in the change history.

Also, recent versions of Perforce do perform checks for changes to files after resolution. So, there may be complaints editing files after some resolve operations have been completed.