Looking for a Perforce cheat sheet after using Git? This is the practical P4 command reference for the everyday workflow: sync files, open work, review a changelist, shelve it for review, resolve integrations, and submit. Perforce is centralized, so the main mental shift is that a client workspace and a pending changelist are first-class parts of the workflow.
Perforce cheat sheet: Git command mapping
| P4 command | Closest Git idea | What it does |
|---|---|---|
p4 set P4PORT=server:1666 | Configure remote | Sets connection variables. Your team may manage these through P4CONFIG instead. |
p4 client | Clone configuration | Creates or edits the client workspace and its depot-to-local view. |
p4 sync | git pull | Brings workspace files to the depot revision selected by the client view. |
p4 edit file | Start modifying a tracked file | Opens a file for edit before you change it. |
p4 add file | git add file | Opens a new local file for addition at submit time. |
p4 delete file | git rm file | Opens a depot file for deletion at submit time. |
p4 move old new | git mv old new | Records a rename as linked move/delete and move/add operations. |
p4 opened | git status | Lists files open in pending changelists. It does not show every untracked local file. |
p4 diff -du | git diff | Shows a unified diff of opened workspace files against their synced revisions. |
p4 reconcile -n | Preview adding modified/untracked/deleted files | Previews what P4 would open after offline or external filesystem changes. |
p4 revert | git restore | Discards open-file changes. Inspect the file and changelist before using it. |
p4 change | Prepare a commit | Creates or edits a pending changelist, including description and jobs. |
p4 submit -c 12345 | git commit + git push | Submits the pending changelist to the central depot. |
p4 shelve -c 12345 | Push a reviewable WIP branch | Stores a pending changelist on the server without submitting it. |
p4 unshelve -s 12345 | Apply a teammate’s WIP change | Brings files from a shelf into your workspace and opens them in a pending changelist. |
p4 integrate + p4 resolve | git merge + resolve | Schedules an integration, then resolves content, file, and branch conflicts before submit. |
First-time setup
Get the server address, user name, and workspace convention from your team first. Do not guess a depot path or overwrite an existing client view. On most teams, you configure the connection, create a client workspace, then sync the branch or stream you are assigned.
p4 set P4PORT=perforce.example.com:1666
p4 set P4USER=your-user
p4 login
p4 client
p4 sync
p4 client opens a client specification. Its Root is your local workspace directory; its View controls which depot paths map into that directory. For streams, your organization may use p4 switch or a stream-bound workspace instead. Ask before changing the view: a wrong mapping can sync much more content than intended.
The everyday P4 workflow
- Sync before work: run
p4 sync. Use a file or depot path when you deliberately want a narrower sync. - Open files before editing: run
p4 edit path/to/file. Usep4 add,p4 delete, andp4 movefor those specific operations. - Inspect the pending work: run
p4 openedandp4 diff -du. - Put related files in a changelist: create it with
p4 change, then move files withp4 reopen -c 12345 path/.... - Submit only when ready: review with
p4 describe -s 12345, then runp4 submit -c 12345.
p4 sync
p4 edit Source/Game/Player.cpp
# make the change
p4 opened
p4 diff -du
p4 change
p4 reopen -c 12345 Source/Game/Player.cpp
p4 describe -s 12345
p4 submit -c 12345
Unlike Git, p4 edit creates server-visible pending work before the file is submitted. Seeing someone else in p4 opened -a //depot/path/file is useful context, but Perforce normally permits concurrent edits; you resolve conflicts when integrating or submitting.
Changelists and shelves
A pending changelist is the unit you describe, review, shelve, and submit. Keep one change focused. A shelf is server-side work in progress: it is ideal for code review or sharing a patch without making it part of the depot history.
# Create/edit a pending changelist, then shelve it
p4 change
p4 shelve -c 12345
# Inspect a shelf and bring it into your workspace
p4 describe -s -S 12345
p4 unshelve -s 12345
# Update or remove the shelf when appropriate
p4 shelve -r -c 12345
p4 shelve -d -c 12345
Unshelving over files you already have open can create unresolved files. Resolve and inspect the result; do not use force options as a first response.
Branches, streams, and integrations
Git users often expect to merge locally and push. In Perforce, an integration is explicitly recorded: choose the target workspace or stream, run an integration command, resolve it, test it, and submit the resulting changelist. Teams with streams may prefer stream commands and policies over raw depot-path integrations.
# Example depot-path workflow; use your team's approved source and target paths
p4 integrate //depot/main/... //depot/release/...
p4 resolve
p4 diff -du
p4 submit
Use p4 resolved to see resolved files and p4 resolve -n to preview unresolved work. Never substitute a generic command from this page for your team’s stream/branch policy.
Recover after offline or external changes
If files changed while you were offline, or a tool wrote files without opening them in P4, start with a preview. p4 status and p4 reconcile -n show what P4 would open for add, edit, or delete. Review that list before running p4 reconcile without -n.
p4 status
p4 reconcile -n
p4 reconcile
p4 opened
p4 diff -du
Useful history and troubleshooting commands
p4 changes -m 10 //depot/project/...lists recent changelists for a path.p4 describe -s 12345shows the files and description for a changelist; add-Sfor a shelf.p4 filelog path/to/fileshows revision history and integration records for a file.p4 where path/to/fileexplains the depot, client, and local mapping.p4 haveshows the revisions currently recorded as synced in the workspace.p4 help commandis the fastest way to confirm the version-specific syntax installed on your machine.
Official Perforce command references
- p4 sync and p4 client
- p4 opened, p4 diff, and p4 reconcile
- p4 shelve and p4 unshelve
- p4 integrate and p4 resolve
For server backups and checkpoints, see the related Perforce Helix Core backup and restore script. Command behavior can vary with server version, permissions, streams, and local policy, so treat your organization’s documentation as authoritative.
Leave a Reply