6

I just submitted a Perforce (p4) changelist that I need to make a small modification to in order to correct a build. How do I unsubmit a recently submitted p4 changelist?

2
  • 1
    In most configuration management systems, I'd submit a new modification with the change you wanted to make in the first place. Is there some reason that this cannot be done?
    – mdpc
    Sep 4, 2012 at 19:23
  • 1
    While that's probably possible in this case, I ask because I'm interested in knowing how to roll back a change in P4 and there aren't many great sources of answers for this via web search.
    – calvinf
    Sep 4, 2012 at 20:17

4 Answers 4

4

You can use p4 sync, and edit/resolve/submit to back out a submitted changelist. For detailed instructions take a look at: https://community.perforce.com/s/article/3474

Hope that helps.

8

Since 2016.2 a new command p4 undo is provided to make it easy to undo one or more changelists.

For example,

p4 undo @12345

This command will open in your workspace the files modified in Changelist 12345. Those files will have the content as of their previous revisions. Once you submit the opened files, the effects of Changelist 12345 are undone.

p4 undo also supports revision ranges to undo multiple changelists at once.

Note that if the files have been modified after the supplied changelist, you will need to p4 sync and p4 resolve the files as normal.

See here for more information: https://www.perforce.com/perforce/doc.current/manuals/cmdref/Content/CmdRef/p4_undo.html

0
# source: https://community.perforce.com/s/article/3474

prevcl=`expr $1 - 1`
echo previous $prevcl

p4 sync @$prevcl

# open all of the edited files
for name in `p4 describe -s $1 | egrep '#[0-9]+ edit$' | cut -f 1 -d# | colrm 1 4`
do
   echo "reverting edits to $name"
   p4 edit $name
done

# add all of the deleted files
for name in `p4 describe -s $1 | egrep '#[0-9]+ delete$' | cut -f 1 -d# | colrm 1 4`
do
   echo "restoring deleted file $name"
   p4 add $name
done

p4 sync @$1
p4 resolve -ay
p4 sync
p4 resolve

# delete all of the added files
for name in `p4 describe -s $1 | egrep '#[0-9]+ add$' | cut -f 1 -d# | colrm 1 4`
do
   echo "removing added file $name"
   p4 delete $name
done
1
  • Please add a bit of description around what this script does, not everyone thinks code is documentation.
    – sysadmin1138
    Apr 10, 2020 at 23:18
0

@Alan Wendt - Thank you, this is very helpful.

Just one addition - sometimes files are moved - not simply add/delete which leads to a bit different suffix. Here is fixed code which also resolved deletion and addition as parts of MOVE operation:

# source: https://community.perforce.com/s/article/3474

prevcl=`expr $1 - 1`
echo previous $prevcl

p4 sync @$prevcl

# open all of the edited files
for name in `p4 describe -s $1 | egrep '#[0-9]+ edit$' | cut -f 1 -d# | colrm 1 4`
do
   echo "reverting edits to $name"
   p4 edit $name
done

# add all of the deleted files
for name in `p4 describe -s $1 | egrep '#[0-9]+ (move/)?delete$' | cut -f 1 -d# | colrm 1 4`
do
   echo "restoring deleted file $name"
   p4 add $name
done

p4 sync @$1
p4 resolve -ay
p4 sync
p4 resolve

# delete all of the added files
for name in `p4 describe -s $1 | egrep '#[0-9]+ (move/)?add$' | cut -f 1 -d# | colrm 1 4`
do
   echo "removing added file $name"
   p4 delete $name
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .