Perforce Command Line Recipes

From PDWiki

Jump to: navigation, search

Helpful Perforce One-liners

About This Project

The page contains a list of handy one line Perforce commands. Most of these can easily be converted into scripts to run from the Perforce GUIs as custom tools. If you have a favorite, please share it with the community! Many of these one liners require a set of Unix tools; the free Cygwin toolkit is one popular solution on Windows. PowerShell examples of many of these commands appear at the bottom of this page. They do not require Unix tools.

Description Delete all empty submitted changelists.
Command p4 changes -s submitted | cut -d " " -f 2 | xargs -n1 p4 change -d -f
Contributor Sam Stafford
Description Find all files containing a given expression. (Variant: to search all revisions use p4 annotate -a instead of p4 print.)
Command p4 print PATH | grep -e EXPR -e "^//" | grep -B1 -e EXPR
Script p4find.bat
Contributor Sam Stafford
Description List all files opened on any client owned by USER, without using p4 opened -a.
Command p4 -Ztag clients | grep -B3 "... Owner USER" | grep "... client" | cut -d ' ' -f 3 | xargs -n1 p4 opened -C
Contributor Sam Stafford
Description List all changelists that contributed via integration to target change CHANGE.
Command p4 files @CHANGE,@CHANGE | sed s/#.*/@CHANGE/ | p4 -x - filelog -m1 | grep "^\.\.\. \.\.\." | grep -v "into" | grep -v "ignored by" | sed "s/.*\/\//\/\//" | p4 -x - changes
Contributor Sam Stafford
Description Delete all jobs matching the pattern "job=DELETEME*".
Command p4 jobs -e "job=DELETEME*" | cut -d " " -f 1 | xargs -n 1 p4 job -d
Contributor Sam Stafford
Description Get the latest version only for files you already have a copy of in your workspace
Command p4 sync <path>#have,head
Script haveSync.pl
Contributor Matt Attaway
Description Open all the files in a submitted changelist for edit
Command p4 files ...@<change num>,<change num> | sed s/\#.*// | p4 -x - edit
Script editFilesInChange.bat
Contributor Matt Attaway
Description Returns output if and only if USER has access to FILE. (Doesn't necessarily work with wildcards.)
Command p4 protects -u USER FILE | tail -n1 | grep -e " //"
Contributor Sam Stafford
Description Simple triggers entry to enforce revertunchanged SubmitOption on client specs.
Command     ru form-in client "sed -i -e s/submitunchanged/revertunchanged/ %formfile%"
Contributor Sam Stafford
Description List all new files under the current directory not opened for add.
Command dir /b /s /a-d | p4 -Ztag -x - add -nf | grep "clientFile" | cut -c16-

find . -type f -print | p4 -Ztag -x - add -nf | grep "clientFile" | cut -c16-

Contributor Sam Stafford
Description Delete all empty submitted changelists. (PowerShell example)
Command p4 changes -s submitted | %{p4 change -d -f $_.split()[1]}
Contributor Philip Kania
Description Find all files containing a given expression. (PowerShell example)
Command p4 print PATH | select-string EXPR,^// | %{if($_ -match "^//"){$f=$_}else{if($f){$f;$f=0};$_}}
Contributor Philip Kania
Description List all files opened on any client owned by USER, without using p4 opened -a. (PowerShell example)
Command p4 clients -uUSER | %{p4 opened -C $_.split()[1]}
Contributor Philip Kania
Description List all changelists that contributed via integration to target change CHANGE. (PowerShell example)
Command p4 files "@CHANGE,@CHANGE" | %{$_ -replace "#.*","@CHANGE"} | p4 -x - filelog -m1 | select-string "^\.\.\. \.\.\." | ?{$_ -notmatch "into" -and $_ -notmatch "ignored by"} | %{$_ -replace ".*//","//"} | p4 -x - changes
Contributor Philip Kania
Description Delete all jobs matching the pattern "job=DELETEME*". (PowerShell example)
Command p4 jobs -e "job=DELETEME*" | %{p4 job -d $_.split()[0]}
Contributor Philip Kania
Description Open all the files in a submitted changelist for edit (PowerShell example)
Command p4 files ...@<change num>,<change num> | %{$_.split("#")[0]} | p4 -x - edit
Contributor Philip Kania
Description Returns True if and only if USER has access to FILE. (PowerShell example)
Command p4 protects -u USER FILE | select-string " //" -quiet
Contributor Philip Kania
Description List all new files under the current directory not opened for add. (PowerShell example)
Command gci -recurse | ?{-not $_.PSIsContainer} | %{$_.FullName} | p4 -ztag -x - add -nf | select-string "clientFile" | %{([string]$_).substring(15)}
Contributor Philip Kania
Personal tools