Perforce Cheat Sheet



A changelist in Perforce is identified by an unique number and contains a list of modified files and a description (among other things). When you inform Perforce that you have created a file, deleted a file or modified a file, such changed files are by default added to a default changelist that has no changelist number.

  • To create a changelist by grabbing the files in the current default changelist:

This opens your default editor to a temporary text file showing an empty description and the list of files from the default changelist. You have to use the editor and provide a description. If you do not want some of the files to be in the changelist you are creating, you can delete those lines in the editor. Once you save the file, the changelist is created with a unique number identifying it. After this command ends, p4 prints out its changelist number, say 123456.

Note that this command moves all the files in the default changelist to the new changelist you created. That is, unless you removed a few of them while creating the changelist.

When you run 'git p4 submit' git-p4 will bring your local Perforce checkout up to date, before running Perforce's edit, and integrate commands (if you've moved or renamed a file), applying your changes, and running 'p4 submit'. It will pre-populate your Perforce submit message with the text you used in the commit message you created for Git. P4V Cheat Sheet The Perforce Visual Client Refresh Get Latest Revision Shift+Ctrl+G Check Out Ctrl+E Drag file from workspace tree to a pending changelist Mark for Add Drag file from workspace tree to a pending changelist Mark for Delete To delete a file, mark it for delete, then submit Submit Changelist Ctrl+S Diff Against Have Revision Ctrl+D.

  • To view all the details of an existing changelist 123456:
  • To move a file on the filesystem to an existing changelist 123456:
  • To move a file from an existing changelist 123456 to the default changelist:
Cheat

Description

  • To view the description of a changelist:
  • To edit the description of an existing changelist 123456:
Cheat

Shelve

Perforce-to-Mercurial Cheat sheet. This table gives hints to some related Perforce and Mercurial commands or concepts. Some commands are the same. Some commands just use different words or syntax. Some commands have no direct counterpart, so there the relation is kind of 'instead you could use this command which does something else'. Perforce Cheat Sheet P4 The Perforce Command-Line Client P4V The Perforce Visual Client p4 add Open a new file to add it to the depot p4 admin Perform administrative operations on the server p4 annotate Print file lines along with their revisions p4 branch Create or edit a branch specification p4 branches Display list of branches.

In fact, the above “cheat sheet” nicely serves the majority of day-to-day use cases. Mercurial users transitioning to Helix Core should feel right at home with very little effort. See for yourself why migrating to Perforce Helix Core is the right choice for Mercurial users.

  • To shelve the files from a changelist 123456:
  • To list the files in a shelved changelist 123456:
  • To update a shelved changelist 123456 with newly updated files from disk:
Sheet

Note that there might be files that are present in the shelve but not present in the pending changelist. This operation will not touch those file in the shelve and those files will continue to exist in the shelve.

  • To replace a shelved changelist 123456 from the pending changelist:

Note how this is different from the -f option. This operation completely replaces the current shelve with the pending changelist. After this operation the shelve and the pending changelist will be perfect replicas of each other. Files that were present in the shelve and not in the pending changelist will be lost.

  • To update a shelved file with a particular changed file from disk:
  • To delete the shelved files of a changelist:
  • To delete a few files from a shelved changelist 123456:

Unshelve

  • To unshelve the files that were shelved from a changelist 123456 back to the same changelist:
  • To unshelve the files that were shelved from a changelist 123456 back to a different changelist 789012:
  • To unshelve the files that were shelved from a changelist 123456 back to the default changelist:

Submit

  • To create a changelist from the default changelist and submit it to your branch in the depot:
  • To submit a changelist 123456 to your branch in the depot:
  • 2Installing
    • 2.1Download clients
  • 3Basic configuration
  • 5Common use cases
  • 6Frequently Asked Questions
  • 7Further reading

Gentle introduction to Perforce

Access to this server is administrated by Henning Christensen who can be reached at the email address hench@dtu.dk.

If you are unfamiliar with Perforce and especially with source control systems, there is a gentle introduction on the perforce website.

Any questions on how to use Perforce (beyond the scope of this document) should be directed to Tommy S. Alstrøm at tsal@dtu.dk

Installing

Download clients

Both visual and command-line clients can be downloaded for Mac, Linux, and Windows on the perforce website:

Direct links to the most common clients are found below. The links point to R17.2 of the command line clients, and R17.3 of the visual clients. Links are last updated 2018.03.06.

Linux Clients

Mac Clients

Windows Clients

Basic configuration

The basic setup procedure is different for the gui and for the command line. Common for both of them is the server address and establishment of trust.

The perforce server has the address

Authentication happens using the portalen username and password.

Upon initial connection, you are asked to approve the fingerprint of the perforce server. The fingerprint should be

If another fingerprint is displayed, you are connecting to the wrong server - contact IT support.

Using the graphical interface

The graphical interface is called P4V. At first connection, you are asked to trust the server. If the fingerprint corresponds to the fingerprint above check the trust button.

As workspace, the workspace should be named '<username>_<something>' (where <something> can be choosen freely).

Using the command line

The command line is configured using environmental variables. These variables are set using the perforce command line. Set the following options

The current loaded settings can always be seen by typing p4 set in command line. Verify your installation by typing (example output)

On linux/mac, these settings are stored in the file ~/.p4enviro. On Windows the settings are stored in the registry. The command line has many configurables, to see most of them, type

The documentation for perforce is built into the program. You can get help by typing

Excluding files from perforce

Usually, there are a lot of different and/or temporary files that you do not want to upload to the perforce server. Perforce implements a procedure using an ignore file that implements rules for which files to ignore. The file uses the same syntax as is known from the .gitignore format. A file called .p4ignore containing all rules for the files that should be ignored. A template .gitignore file can be found in the archive.

In order to use an ignore file, use

The effect of the ignore file can be explored using the p4 ignores command. E.g. to query whether or not a file is ignored, type

In order to bypass the ignore list when adding files, use p4 add -I.

Read more about the p4ignore file format in the perforce command reference.

Archive structure

The perforce server can be accessed publicly using

The general layout is as follows

The data depot comp-data is a special depot, in the sense that there exists a read-only copy of the latest revision of this depot in the folder called /dtu-compute/comp-data/ accessible from DTU Compute grid, gbar and hpc-cluster.

Common use cases

These use cases are described as commands, but most of them are as easily carried out using the graphical user interface. For any single command, you can always type p4 help <cmd> to get help.

Adding files

Adding files to perforce is a two step procedure. First the files are added using a p4 add command, then the files are uploaded using a p4 submit command. To do this in command line, type

To check that these files will land in the perforce depot the expected place, type

You will see these files are adding to the default changelist. To submit these files type

The above command will submit all changes that currently reside on the default changelist. If you wish to only submit files from the current directory, use

The '...' is a special path known to perforce that means everything from here and beneath and is very commonly used.

Deleting a file

To remove a file from perforce, a new revision of a file - namely a deletion is uploaded. As such, deleting a file will never permanently delete the file, and you can always go back and get older revisions. In that way, obsolete files can safely be deleted without loosing the history. To perform the delete, type

Renaming files

Perforce Git Cheat Sheet

Renaming files in perforce is essentially a copy and a delete. As with the delete case, the file with the old name will continue to be in perforce. To rename a file, type

You can also call the command p4 rename, which is a synonym for p4 move.

Merging

Merging is carried out using the p4 integrate or p4 merge command. p4 merge is a synonym for p4 integrate where certain flags are set. As such, there is truly only one merge command. This procedure is by far easiest to carry out using the GUI.

Performing copy / Branching

Perforce Cheat Sheet Pdf

In Perforce, the branch model is to perform a copy. As such, any single file with the complete depot path always belongs to one particular branch. Once a file is copied, it is branched. That simply means that perforce keeps track of the origin of the file and that makes merging changes later a lot easier. Copying is carried out using the p4 copy command:

Syncronizing perforce with your current working copy

In case you make changes to files without 'telling perforce', there is an easy command to get perforce up to speed. Two commands exist:, p4 status which will give you a status of what is currently out of sync, and the p4 rec which will put out changed on the default workspace. In the gui, select the option called 'Reconcile offline work' to get an interactive experience.

The commands take file paths, so at any time you can always narrow down your reconcile to specific files, e.g. if you want to only add any changed matlab files to your default changelist, type

Performing server-side copy

Perforce supports two different approaches to server-side copy. Using the -v flag to p4 copy, p4 merge, or p4 integrate will perform the copy, merge, or integrate without syncing the files to the client. However, if one performs this action to a target outside the client view, perforce will give the error 'File(s) not in client view'

Perforce supports server-side copy of files outside the client workspace. This is carried out using the p4 populate command:

Frequently Asked Questions

The client shows I don't have a file even though I do, how do I handle it?

This scenario can happen if you by other means move files/folders that are under Perforce source control. Perforce has a 'have' database that contains which files are retrieved in which revision on each workspace, p4 have will show you the current 'have list' for the chosen workspace. The p4 have list can be out of sync:

  1. You create a new workspace that points to files under perforce source control
  2. You move files by other means (e.g copy files to grid, or sync files using dropbox) to other machines and use different workspaces.
  3. Manually delete files

To resolve, run

How do I sync a directory that does not exist on my computer yet?

If the directory exists on the perforce server but not on your computer, and you would like to do a narrow sync, do the following:

Or from the directory you have - e.g. if you have a directory called perforce and you wish to sync a subdirectory called public, do the following:

On Windows, I get the error 'too long filename', how do I fix that?

The windows file system does per default only support path names of length up to 260. If you set the environmental variable

Sheet

both the command line tool and the visual client can operate with long file names. If you only use the command line, this option can be set in the configuration file (p4enviro).

You can read more about it on the perforce website.

Why are all my files read-only?

The default workflow implemented by Perforce is to set all files as read only. The idea in the workflow is

  1. Notify the Perforce server that you intend to edit the file.
  2. Once you're done editing you submit the file using a changelist.

Why do I get a 'file not in view' error message?

This happens if you try to operate on files that are not defined in the workspace (also called client view). Typically the error occurs because you are copying files to a new place where you have not defined a view yet. To perform copying to destinations where you do not want to checkout the files, use the p4 populate command.

This can also happen if you unexpectedly change workspace. Use the p4 set command to verify that you are using the expected workspace, and the p4 where ... command to verify where the current location will be.

Why is my question not in the FAQ?

Nobody has asked this question before. Contact Tommy S. Alstrøm at tsal@dtu.dk with your question, and an answer will be provided.

Further reading

External material for understanding Perforce

Perforce Commands Cheat Sheet

Perforce cheat sheet.

Source Depot Commands List

Tips for subversion users

Perforce provides a list of subversion command and their perforce counterpart here:Reference: http://answers.perforce.com/articles/KB/2953

Tips for git users

There are a few approaches git users can take on perforce:

  1. Migrate to perforce
  2. Have the same repo under both perforce and git revision control
  3. Retain a complete git eco system

For a complete migration to perforce, use the git - perforce command comparison.

Perforce Cheat Sheet

To have the same repo under both perforce and git revision control, one simply commits to both git and perforce. This basically means that local branching is carried out using git only and the master branch only is commited to perforce. The other approach is to set up the git client to connect to perforce. This is detailed in chapter 9 in the pro git 2 book.

Finally, once can reside in a complete git environment, and create git repos based on perforce files. This is carried out using our gitswarm server, however this server is still to be put into production mode.

Clearcase Commands Cheat Sheet

Retrieved from 'https://itswiki.compute.dtu.dk/index.php?title=Perforce&oldid=3532'