When "p4 copy -f" helps a lot?

69 views Asked by At

The manual says that -f means

Force the creation of extra revisions in order to explicitly record that files have been copied. Deleted source files are copied if they do not exist in the target, and files that are already identical are copied if they are not connected by existing integration records.

Honestly, I don't quite understand when p4 copy -f can be very useful. Could someone please show me some simple examples of the use cases of p4 copy -f?

Thank you.

1

There are 1 answers

2
Samwise On

If you’ve never encountered a situation where p4 copy -f seems like it might be useful, count yourself lucky and forget about it; there are a number of options in Perforce that are only ever useful if you’ve already dug yourself a hole and are determined to keep digging, and this is one of them.

That said, the classic case is:

  1. Add foo in A.
  2. Branch A to B.
  3. Delete foo in B.
  4. Branch B to C.
  5. Merge C to A.

If foo never existed in C, it will not be included in a merge from C, so the change from step 3 is “lost” during the merge in step 5. Using p4 copy -f in step 4 prevents this by creating a dummy file in C that can propagate the delete to A.

Note that reparenting branches like this (going from A to B to C to A, rather than going from A to B to A) is not typically recommended as a best practice because it makes merging much more complicated in general.