LinuxCommandLibrary

p4

Manage files using Perforce Helix Versioning Engine

TLDR

Log in to the Perforce service

$ p4 login -a
copy

Create a client
$ p4 client
copy

Copy files from depot into the client workspace
$ p4 sync
copy

Create or edit changelist description
$ p4 change
copy

Open a file to edit
$ p4 edit -c [changelist_number] [path/to/file]
copy

Open a new file to add it to the depot
$ p4 add
copy

Display list of files modified by changelist
$ p4 describe -c [changelist_number]
copy

Submit a changelist to the depot
$ p4 submit -c [changelist_number]
copy

SYNOPSIS

p4 [global_options] command [command_options] [command_arguments]

The p4 command typically starts with global options that define connection parameters or output format, followed by a specific Perforce command (e.g., "sync", "submit", "edit"), and then options and arguments relevant to that specific command.

PARAMETERS

-p host:port
    Specifies the Perforce server address and port to connect to. Can also be set via the P4PORT environment variable.

-u username
    Specifies the username for the Perforce connection. Can also be set via the P4USER environment variable.

-c clientname
    Specifies the client workspace (or 'client spec') to use for operations. Can also be set via the P4CLIENT environment variable.

-H hostname
    Specifies the host name for the local machine, overriding the default determined by the client.

-Ztag
    Produces tagged output, which is a structured, machine-readable format often used for scripting and parsing p4 command output.

-d charset
    Specifies the character set for the client, used for internationalization. Can also be set via the P4CHARSET environment variable.

-r retries
    Specifies the number of connection retries to attempt if the server connection fails.

-s
    Silences informational messages, showing only errors and warnings.

DESCRIPTION

p4 is the command-line client for Perforce Helix Core, a comprehensive version control and collaboration platform widely used for managing source code, large digital assets, and binary files in various industries, including game development, semiconductors, and software development. Unlike decentralized systems like Git, Perforce operates as a centralized version control system where all files and their history reside on a central server.

The p4 client allows users to interact with the Helix Core server to perform essential SCM operations such as adding, editing, deleting, submitting, syncing, branching, merging, and viewing file history. It is particularly renowned for its performance in handling large numbers of files and very large file sizes, making it suitable for projects with massive repositories. The command-line interface provides granular control over workspace configuration, changelist management, and server administration.

CAVEATS

Perforce is a centralized system, meaning a server connection is generally required for most operations. Network latency can significantly impact performance, especially over wide area networks. Understanding workspace views and stream definitions is crucial for effective use. Resolving conflicts, particularly with large binary files, can sometimes be challenging without proper tools or defined workflows. Its default atomic commit model can require careful planning for very large or complex changes.

ENVIRONMENT VARIABLES

Many global options for p4 can be conveniently set using environment variables, such as P4PORT, P4USER, P4CLIENT, and P4CHARSET. These variables define default connection parameters, reducing the need to specify them with every command and simplifying scripting.

COMMON WORKFLOWS

Typical p4 workflows involve using p4 sync to get the latest files from the server, p4 edit to open files for modification, p4 add or p4 delete for new or removed files, p4 revert to discard local changes, p4 diff to view changes, and finally p4 submit to commit changes to the server as an atomic changelist.

HISTORY

Perforce Software, Inc. was founded in 1995, and the p4 client has been the primary command-line interface for its Helix Core (formerly Perforce SCM) version control system since its inception. Initially developed to handle large and complex software development projects, Perforce gained significant traction for its robust performance with large binary files and its support for atomic change lists, which bundle multiple file modifications into a single, indivisible transaction. Over the years, it has evolved to incorporate features like streams (a branching/merging paradigm), shelving, and deep integration with various CI/CD pipelines, maintaining its reputation as a high-performance solution for enterprise-scale version control.

SEE ALSO

git(1), svn(1), cvs(1), rcs(1)

Copied to clipboard