如何取消提交先前提交的 Perforce 变更列表?

如何取消提交先前提交的 Perforce 变更列表?

我刚刚提交了一个 Perforce (p4) 变更列表,我需要对其进行小修改以更正构建。如何取消提交最近提交的 p4 变更列表?

答案1

您可以使用 p4 sync 和 edit/resolve/submit 来撤销已提交的变更列表。有关详细说明,请查看:https://community.perforce.com/s/article/3474

希望有所帮助。

答案2

自 2016.2 起,p4 undo提供了一个新命令,可以轻松撤消一个或多个变更列表。

例如,

p4 undo @12345

此命令将在您的工作区中打开变更列表 12345 中修改的文件。这些文件将具有其先前修订的内容。一旦您提交打开的文件,变更列表 12345 的效果将被撤消。

p4 undo还支持修订范围以一次撤消多个变更列表。

请注意,如果文件在提供的变更列表之后已被修改,则您需要像平常一样p4 sync修改p4 resolve文件。

浏览此处获取更多信息:https://www.perforce.com/perforce/doc.current/manuals/cmdref/Content/CmdRef/p4_undo.html

答案3

# 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

答案4

@Alan Wendt - 谢谢,这非常有帮助。

只需添加一点 - 有时文件会被移动 - 而不仅仅是添加/删除,这会导致后缀略有不同。以下是修复的代码,它还将删除和添加解析为 MOVE 操作的一部分:

# 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

相关内容