Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Perforce p4 Command-Line Cheat Sheet: Query, Sync, Integrate, and Admin Workflows

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.

perforce-command-line-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 patternStart withExample
What are the filenames that match a path or revision?p4 files or p4 havep4 files //depot/...#head
p4 files //depot/...@label
p4 have
What changed in my workspace copy versus depot?p4 diffp4 diff file.c
p4 diff -se
What differs between two depot files, paths, or revisions?p4 diff2p4 diff2 file1.c#1 file1.c#2
p4 diff2 dir1/...@now dir1/...@2000/01/02
Tell me everything about changelist N.p4 describep4 describe 1231
Show changelists for a path, file, or integration history.p4 changesp4 changes //depot/eng/prodxyz/...
p4 changes -i //depot/eng/prodxyz/...
Show all revisions and integrations of one file.p4 filelogp4 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.

SpecifierTypical meaning in this cheat sheetExample
#headHead revision of a filep4 sync file.java#head
@nowCurrent state at the present timep4 sync file.java@now
@YYYY/MM/DDFile state as of a datep4 sync file.java@2000/04/15
@labelRevisions captured by a labelp4 sync file.java@xyz
@123456Revisions as of a changelistp4 sync file.java@123456
@clientRevision associated with a named client workspacep4 sync file.java@jab.work
#haveRevision currently in your workspacep4 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.

GoalCommand patternNotes
Push from base codeline to release codelinep4 integ -b branchName [file/revision args]Use changelist ranges like //...@129,@134 for selective pushes.
Push from release back to basep4 integ -b branchName -r [file/revision args]-r reverses source and target from the branch spec.
Compare branch spec source and targetp4 diff2 -b branchNameUseful before or after larger merges.
List available branch specsp4 branchesMost 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

CommandUseAccess level
p4 admin checkpointCreate a checkpointAdministrator (super)
p4 protectEdit protections/permissionsAdministrator
p4 protectsShow effective permissionsAny user with command access
p4 client (set compress)Enable client-side network compression in workspace optionsWorkspace owner

Best practices and common pitfalls

  • Check before submit: run p4 opened and p4 diff so your changelist contains only intended files.
  • Use p4 revert carefully: 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 ... and p4 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.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
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.

Related Posts

Perforce 2014 Server Upgrade Runbook: Verify, Checkpoint, Restore, and Validate

This guide converts the original Perforce 2014 upgrade notes into a practical runbook for production admins. It covers pre-checks, checkpoint-based recovery, post-upgrade verification, and migration cautions.

Read More

Perforce Server Disk Cleanup and Repository Size Management: A Safe, Practical Playbook

Running out of storage on a Perforce (Helix Core) server can quickly become an availability risk. This guide shows a safer cleanup workflow: measure space first, compare options, then execute changes with minimal operational risk.

Read More

Perforce Interview Prep: Essential p4 Commands for Workspaces, Changelists, and Admin Tasks

A practical Perforce interview refresher focused on high-value commands and admin concepts from real usage. Learn how to query changelists, exclude files, use metadata options, and avoid risky data-removal mistakes.

Read More

Perforce Training Guide: Hands-On P4 Curriculum for Users, SCM Engineers, and Release Teams

This revised guide turns a legacy Perforce training announcement into a practical reference for planning team enablement. It summarizes the syllabus, lab workflow, core P4 command areas, and post-training adoption practices.

Read More

Perforce Backup Commands: Checkpoints, Journal Rotation, and Restore Workflow

This guide explains the core Perforce backup commands from the original post and how to use them in a practical backup and restore workflow. You will get a command reference, comparison tables, and ready-to-adapt examples.

Read More

Perforce Tools Explained: Clients, Servers, Plug-ins, and Utilities (Legacy 2012 Reference)

This updated reference explains the Perforce tools listed in the original 2012 post, what each component does, and how they fit together. It also includes a practical p4 CLI workflow and cautions for legacy or renamed components.

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Jason Mitchell
Jason Mitchell
3 months ago

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.

1
0
Would love your thoughts, please comment.x
()
x