Perforce command names can look similar when you are under delivery pressure. This updated cheat sheet helps developers, release engineers, and administrators quickly choose the right p4 command for searching history, syncing files, integrating codelines, and managing labels.
Originally published on 2009-06-20; fully revised and updated.
Original reference post: Perforce Web References & Cheatsheet.

Command chooser for Perforce data-mining questions
When the question is clear, the command choice is usually straightforward. Use this mapping to decide whether you need file names, changelists, detailed history, or content differences.
| Question pattern | Start with | Example |
|---|---|---|
| What are the filenames that match a path or revision? | p4 files or p4 have | p4 files //depot/...#headp4 files //depot/...@labelp4 have |
| What changed in my workspace copy versus depot? | p4 diff | p4 diff file.cp4 diff -se |
| What differs between two depot files, paths, or revisions? | p4 diff2 | p4 diff2 file1.c#1 file1.c#2p4 diff2 dir1/...@now dir1/...@2000/01/02 |
| Tell me everything about changelist N. | p4 describe | p4 describe 1231 |
| Show changelists for a path, file, or integration history. | p4 changes | p4 changes //depot/eng/prodxyz/...p4 changes -i //depot/eng/prodxyz/... |
| Show all revisions and integrations of one file. | p4 filelog | p4 filelog file.java |
p4 files //depot/...#have
p4 files //depot/...@1541
p4 changes file.c
p4 describe 1231
p4 filelog file.javaCode language: JavaScript (javascript)
Daily workspace workflow
This is the common developer loop: configure workspace, sync, open files, review, and submit.
flowchart TD
A[Create or update workspace] --> B[Sync files from depot]
B --> C[Open files for add edit or delete]
C --> D[Review local changes]
D --> E{Ready to publish}
E -- no --> F[Continue editing or revert]
F --> C
E -- yes --> G[Submit changelist]
G --> H[Integrate or share with team]
p4 set P4CLIENT=my_workspace
p4 client -t 1.0dev
p4 sync //depot/eng/...
p4 edit relnotes.txt
p4 diff relnotes.txt
p4 submit relnotes.txt
p4 revert -a
p4 revert file.javaCode language: JavaScript (javascript)
Revision specifiers quick reference
Many Perforce commands become much more useful when you add a revision specifier.
| Specifier | Typical meaning in this cheat sheet | Example |
|---|---|---|
#head | Head revision of a file | p4 sync file.java#head |
@now | Current state at the present time | p4 sync file.java@now |
@YYYY/MM/DD | File state as of a date | p4 sync file.java@2000/04/15 |
@label | Revisions captured by a label | p4 sync file.java@xyz |
@123456 | Revisions as of a changelist | p4 sync file.java@123456 |
@client | Revision associated with a named client workspace | p4 sync file.java@jab.work |
#have | Revision currently in your workspace | p4 sync -f file.java#have |
Branching and selective integration
Use branch specifications consistently, then drive integrations with p4 integ (shorthand for p4 integrate) and inspect branch differences with p4 diff2 -b.
| Goal | Command pattern | Notes |
|---|---|---|
| Push from base codeline to release codeline | p4 integ -b branchName [file/revision args] | Use changelist ranges like //...@129,@134 for selective pushes. |
| Push from release back to base | p4 integ -b branchName -r [file/revision args] | -r reverses source and target from the branch spec. |
| Compare branch spec source and target | p4 diff2 -b branchName | Useful before or after larger merges. |
| List available branch specs | p4 branches | Most useful when teams standardize branch spec naming. |
# Base to release
p4 integ -b prodxyz-1.0.1 //...@=1232
p4 integ -b prodxyz-1.0.1 //...@129,@134
p4 integ -b prodxyz-1.0.1
# Release to base (reverse mapping from branch spec)
p4 integ -b prodxyz-1.0.1 -r @=1235
p4 integ -b prodxyz-1.0.1 -r //...@127,@128
p4 integ -b prodxyz-1.0.1 -r
# Branch comparison
p4 diff2 -b prodxyz-1.0.1Code language: PHP (php)
Labels and release snapshots
Labels provide a named snapshot of file revisions. The original cheat sheet uses a two-step pattern: create label metadata, then populate label contents.
# Create and populate a label
p4 label xxx
p4 labelsync -l xxx
p4 labelsync -l xxx file1 file2
# Copy one label's contents into a new label
p4 label -t xxx abc
p4 labelsync -l abc //...@xxxCode language: PHP (php)
Working offline and reconciling later
The original guide includes a practical recovery pattern for edits made while disconnected: detect edits, deletions, and additions, then open files in Perforce accordingly.
p4 diff -se | p4 -x - edit
p4 diff -sd | p4 -x - delete
find . -type f -print | p4 -x - add
p4 opened
p4 diffCode language: JavaScript (javascript)
Administration commands from the original sheet
| Command | Use | Access level |
|---|---|---|
p4 admin checkpoint | Create a checkpoint | Administrator (super) |
p4 protect | Edit protections/permissions | Administrator |
p4 protects | Show effective permissions | Any user with command access |
p4 client (set compress) | Enable client-side network compression in workspace options | Workspace owner |
Best practices and common pitfalls
- Check before submit: run
p4 openedandp4 diffso your changelist contains only intended files. - Use
p4 revertcarefully: the original sheet explicitly warns it is irreversible for unopened/unsubmitted work. - Be cautious with selective integrations: review merge choices carefully, especially when reversing flow with
-r. - Standardize branch specs: consistent naming makes
p4 integ -b ...andp4 diff2 -b ...much safer to reuse. - Verify behavior against your installed Perforce version: some notes in the 2009-era sheet reference older releases and may differ in modern environments.
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals
In larger Perforce environments, knowing the commands is only the first step; maintaining a clean and efficient workflow becomes equally important. As more developers and automated systems interact with the repository, issues like unmanaged workspaces, unclear changelist ownership, and outdated files can create unnecessary complexity. Establishing proper repository practices and regular maintenance helps teams avoid confusion and improves overall development efficiency.
From an operational perspective, Perforce works best when combined with structured review processes, automation, and clear collaboration guidelines. Connecting source control activities with CI/CD workflows and tracking repository health can help teams identify problems early and keep release processes stable as projects and teams continue to grow.