Perforce: Find source changelist for a branch

branching-and-mergingperforceversion control

Short version:

After branching in P4, how can I find out the "source" changelist of the branch?

Long version:

Let's say I have a main branch of my project at

//project/main/...

The latest changelist submitted here is @123, when I decide to create a branch for release 1.0 in

//project/1.0/...

From P4V, a new changelist is created (say @130), resolved and submitted.

From the CLI, it would look something like this:

p4 integrate -c 123 -o //project/main/... //project/1.0/...
p4 submit

Later, I look at the changelists under //project/1.0, and see the @130 changelist containing a lot of branched files.
How can I find out the changelist no. that this was originally branched from (that is, @123) ?

Best Answer

p4 changes will display a list of submitted changelists, optionally filtered to a specific path.

p4 changes //project/main/...
Change 123 ... 'Very last change.'
Change 122 ... 'Next-to-last change.'
Change 100 ... 'Only two changes to go...'
...

No surprise there, but, as you've found, p4 changes is less helpful when you integrate all those changes in a single change:

p4 changes //project/1.0/...
Change 130 ... 'Integrated everything from main.'

The trick is to use the -i option which includes any changelists integrated into the specified files.

p4 changes -i //project/1.0/...
Change 130 ... 'Integrated everything from main.'
Change 123 ... 'Very last change.'
Change 122 ... 'Next-to-last change.'
Change 100 ... 'Only two changes to go...'
...

To get exactly what you want (123) you'll need to write a script which filters the output from p4 changes -i //project/1.0/... to remove any change listed by p4 changes //project/1.0/... (and then take the most recent remaining change).

(When exploring, I frequently also find the -m max option useful. This limits changes to the 'max' most recent. This helps your output not flow offscreen when there are many changes.)