Moving Selected Opened Files between Pending Changelists

TASK

How do I move a subset of files from one pending changelist to another, based on extension?


SOLUTION

Generate a list of files to be moved and utilize the p4 reopen command to move the files to a different changelist. Executed under Linux or UNIX and from the client root, the following command sequence works in most instances:

 p4 -Ztag describe cl_from | grep "^\.\.\. depotFile" | cut --delimiter="/" -f4- | grep "\.extension_in_question" | p4 -x - reopen -c cl_destination

For example if you want to move all ".txt" files from changelist 86 to 87, you can run the following commands:

p4 describe 86
Change 86 by ray@perforce on 2007/11/05 17:14:30 *pending*

Affected files ...

... //depot/bar.txt#4 edit
... //depot/foo.txt#1 edit
... //depot/footobar.txt#1 edit
... //depot/mtd#1 edit
... //depot/mtd2#2 edit
... //depot/another.odt#1 edit
... //depot/bay#1 edit
... //depot/test.sh#2 edit

p4 -Ztag describe 86 | grep "^\.\.\. depotFile" | cut -d "/" -f4- | grep "\.txt" | p4 -x - reopen -c 87
//depot/bar.txt#4 - reopened; change 87
//depot/foo.txt#1 - reopened; change 87
//depot/footobar.txt#1 - reopened; change 87