Perforce for Git Users

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 commandClosest Git ideaWhat it does
p4 set P4PORT=server:1666Configure remoteSets connection variables. Your team may manage these through P4CONFIG instead.
p4 clientClone configurationCreates or edits the client workspace and its depot-to-local view.
p4 syncgit pullBrings workspace files to the depot revision selected by the client view.
p4 edit fileStart modifying a tracked fileOpens a file for edit before you change it.
p4 add filegit add fileOpens a new local file for addition at submit time.
p4 delete filegit rm fileOpens a depot file for deletion at submit time.
p4 move old newgit mv old newRecords a rename as linked move/delete and move/add operations.
p4 openedgit statusLists files open in pending changelists. It does not show every untracked local file.
p4 diff -dugit diffShows a unified diff of opened workspace files against their synced revisions.
p4 reconcile -nPreview adding modified/untracked/deleted filesPreviews what P4 would open after offline or external filesystem changes.
p4 revertgit restoreDiscards open-file changes. Inspect the file and changelist before using it.
p4 changePrepare a commitCreates or edits a pending changelist, including description and jobs.
p4 submit -c 12345git commit + git pushSubmits the pending changelist to the central depot.
p4 shelve -c 12345Push a reviewable WIP branchStores a pending changelist on the server without submitting it.
p4 unshelve -s 12345Apply a teammate’s WIP changeBrings files from a shelf into your workspace and opens them in a pending changelist.
p4 integrate + p4 resolvegit merge + resolveSchedules 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

  1. Sync before work: run p4 sync. Use a file or depot path when you deliberately want a narrower sync.
  2. Open files before editing: run p4 edit path/to/file. Use p4 add, p4 delete, and p4 move for those specific operations.
  3. Inspect the pending work: run p4 opened and p4 diff -du.
  4. Put related files in a changelist: create it with p4 change, then move files with p4 reopen -c 12345 path/....
  5. Submit only when ready: review with p4 describe -s 12345, then run p4 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 12345 shows the files and description for a changelist; add -S for a shelf.
  • p4 filelog path/to/file shows revision history and integration records for a file.
  • p4 where path/to/file explains the depot, client, and local mapping.
  • p4 have shows the revisions currently recorded as synced in the workspace.
  • p4 help command is the fastest way to confirm the version-specific syntax installed on your machine.

Official Perforce command references

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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *