Search code examples
perforcerollbackintegratebackout

P4: I made a mistake renaming files and loose its history. How can I fix it?


I was asked to change the extension of a file to another like:

file.a --> file.b

The thing I did (wrong) was something like :

  cp file.a file.b
  p4 add file.b
  p4 delete file.a

And then submitted to my branch. The thing is my team want to keep the history of file.a on file.b. I didn't know about p4 move until now, so I screwed up.

If I rollback my changes and do a p4 move file.a file.b, there will still on its history the 'deletion issue' when I integrate to the main branch right?

Is there a way to recover the first file.a from the main branch and replace file.b with it? (and then do the p4 move)

Thanks a lot guys.

PS: I'm new using p4


Solution

  • I'll assume for example's sake that file.a#4 was the last rev before it got deleted. I'll also assume you're on a fairly current version of p4d...

    First, undo your previous change.

    p4 sync file.a#4
    p4 add file.a
    p4 delete file.b
    p4 submit -d "undo previous change"
    

    Note that when you re-add a file by syncing to an old rev first, the history keeps an integration pointer showing that the new "add" rev is connected to the old rev (you can see this if you run "p4 filelog file.a"). This will make things go smoother when you integrate back to the main branch, since otherwise it would look like file.a was a brand new file.

    Now that file.a is back (and still connected to the main branch via integration history), and file.b is deleted, you can "move" file.a to file.b with no impediments:

    p4 edit file.a
    p4 move file.a file.b
    p4 submit -d "moving .a to .b"
    

    Now when you integrate back to the main branch and run "p4 resolve", the same "move" will happen on the mainline, and if any other changes have happened to file.a on the mainline they'll be merged with your file.b rename (rather than what you were probably running into before, with the file.a delete conflicting with other changes while your "new" file.b just wanted to get branched in as an independent file).