Catalog / Perforce Cheat Sheet

Perforce Cheat Sheet

A comprehensive cheat sheet for Perforce, covering essential commands and workflows for version control.

Basic Commands

Connecting to the Server

p4 info

Displays information about the Perforce server and client configuration.

p4 login

Authenticates the user with the Perforce server.

p4 set P4PORT=<server:port>

Sets the Perforce server address. Example: p4 set P4PORT=perforce.example.com:1666

p4 set P4USER=<username>

Sets the Perforce username. Example: p4 set P4USER=johndoe

p4 set P4CLIENT=<workspace>

Sets the Perforce workspace (client). Example: p4 set P4CLIENT=johndoe_dev

Workspace Management

p4 client

Opens the client specification form for editing. Allows you to configure the workspace.

p4 clients

Lists all client workspaces known to the Perforce server.

p4 sync

Synchronizes the workspace with the latest version of files from the depot.

p4 sync <file(s)>

Synchronizes specific files to the latest version.

p4 sync @label

Synchronizes the workspace to a specific label.

p4 sync #have

Synchronizes the workspace to the revisions you had previously synced.

Adding and Deleting Files

p4 add <file(s)>

Marks new files for addition to the depot.

p4 delete <file(s)>

Marks files for deletion from the depot.

p4 reconcile

Detects files that have been added, deleted, or modified outside of Perforce and prepares them for submission.

Change Management

Making Changes

p4 edit <file(s)>

Opens files for editing. Required before modifying a file under Perforce control.

p4 revert <file(s)>

Discards changes made to opened files, reverting them to the last synced version.

p4 diff <file(s)>

Displays the differences between the workspace version and the depot version of a file.

p4 resolve <file(s)>

Resolves conflicts between the workspace version and the depot version of a file after an update or merge. Important to do before submitting.

Submitting Changes

p4 change

Opens a new changelist for grouping related changes.

p4 submit

Submits the opened files in the current or specified changelist to the depot.

p4 submit -d "<description>"

Submits the changes with a description from command line.

p4 changes

Lists recent changelists.

p4 describe <changelist#>

Describes a specific changelist, showing the files included and the description.

Branching and Merging

p4 integrate <fromFile> <toFile>

Prepares files for merging changes from one branch to another.

p4 merge <fromFile> <toFile>

Merges changes from one branch to another (older command).

p4 resolve

Resolves any conflicts after the integration/merge. Crucial before submitting!

p4 branch

Creates a new branch specification.

Advanced Operations

Labels and Attributes

p4 label

Creates or modifies a label specification.

p4 labels

Lists available labels.

p4 tag <file(s)>@<label>

Attaches a label to specific file revisions.

p4 attribute

Sets or retrieves file attributes.

Streams

p4 streams

Lists available streams.

p4 stream

Creates or modifies a stream specification.

p4 switch <stream>

Switches the workspace to a different stream.

p4 merge and p4 copy

Used for propagating changes between streams.

User and Group Management

p4 user

Creates or modifies a user specification (requires admin privileges).

p4 group

Creates or modifies a group specification (requires admin privileges).

p4 users

Lists all users.

Troubleshooting and Tips

Common Issues

Conflicts during submit: Always p4 resolve before submitting. Use p4 diff to understand the changes.

Workspace out of date: Ensure you p4 sync regularly to keep your workspace up-to-date.

Permissions issues: Check file permissions and ensure the Perforce user has appropriate access.

Network connectivity: Verify network connectivity to the Perforce server. Use p4 info to check the connection.

Best Practices

Atomic Changesets: Group related changes into a single changelist for better tracking and management.

Descriptive Comments: Provide clear and concise descriptions for each changelist.

Regular Synchronization: Keep your workspace synchronized with the depot to avoid conflicts and integration issues.

Branching Strategy: Develop a clear branching strategy to manage different development streams and releases.

Command Aliases (Example)

You can create aliases for frequently used commands for efficiency. For example, in bash:

alias psync='p4 sync'
alias psubmit='p4 submit'