Perforce Command Line Global Options

<!– .style1 { font-size: 24px; font-weight: bold; } –>

Perforce Command Line Global Options

Global options for Perforce commands; these options can be supplied on the command line before any Perforce command.

Syntax
p4 [-cclient -ddir -Hhost -pport -Ppass -uuser -xfile -Ccharset -Qcharset -Llanguage] [-G] [-s] [-z tag] cmd [args …]
p4 -V
p4 -h

 

Options
 
-c client
Overrides any P4CLIENT setting with the specified client name.
-d dir
Overrides any PWD setting (i.e. current working directory) and replaces it with the specified directory.
-G
Causes all output (and batch input for form commands with -i) to be formatted as marshalled Python dictionary objects. This is most often used when scripting.
-H host
Overrides any P4HOST setting and replaces it with the specified hostname.
-p port
Overrides any P4PORT setting with the specified port number.
-P pass
Overrides any P4PASSWD setting with the specified password.
-s
Prepends a descriptive field (for example, text:, info:, error:, exit:) to each line of output produced by a Perforce command. This is most often used when scripting.
-u user
Overrides any P4USER, USER, or USERNAME setting with the specified user name.
-x file
Instructs Perforce to read arguments, one per line, from the specified file. If file is a single hyphen (-), then standard input is read.
-C charset
Overrides any P4CHARSET setting with the specified character set.
-Q charset
Overrides any P4COMMANDCHARSET setting with the specified character set.
-L language
This feature is reserved for system integrators.
-z tag
Causes output of many reporting commands to be in the same tagged format as that generated by p4 fstat.
-V
Displays the version of the p4 client program and exits.
-h
Displays basic usage information and exits.

 

Usage Notes
Be aware that the global options must be specified on the command line before the Perforce command. Options specified after the Perforce command will not be interpreted as global options, but as options for the command being invoked. It is therefore possible to have the same command line option appearing twice in the same command, being interpreted differently each time.
For example, the command p4 -c anotherclient edit -c 140 file.c will open file file.c for edit in pending changelist 140 under client workspace anotherclient.
The -x option is useful for automating tedious tasks; a user adding several files at once could create a text file with the names of these files and invoke p4 -x textfile add to add them all at once.
The -x option can be extremely powerful – as powerful as whatever generates its input. For example, a UNIX developer wishing to edit any file referring to an included file.h file, for instance, could grep -l file.h *.c | cut -f1 -d: | p4 -x – edit.
In this example, the grep command lists occurrences of file.h in the *.c files, the -l option tells grep to list each file only once, and the cut command splits off the filename from grep’s output before passing it to the p4 -x command.
The -s option can be useful in automated scripts.
For example, a script could be written as part of an in-house build process which executes p4 -s commands, discards any output lines beginning with “info:”, and alerts the user if any output lines begin with “error:”.
Python developers will find the -G option extremely useful for scripting. For instance, to get a dictionary of all fields of a job whose ID is known, use the following:
job_dict = marshal.load(os.popen(‘p4 -G job -o ‘ + job_id, ‘rb’))
In some cases, it may not be intuitively obvious what keys are used by the client program. If you pipe the output of any p4 -G invocation to the following script, you will see every record printed out in key/value pairs:
Tagged : / / / / /

Perforce Command Line

Command

Description

p4 add
Open file(s) in a client workspace for addition to the depot.
p4 admin
Perform administrative operations on the server.
p4 branch
Create or edit a branch specification and its view.
p4 change
Create or edit a changelist specification.
p4 changelists
List submitted and pending changelists.
p4 changelist
Create or edit a changelist specification.
p4 client
Create or edit a client workspace specification and its view.
p4 clients
List all client workspaces currently known to the system.
p4 delete
Open file(s) in a client workspace for deletion from the depot.
p4 depot
Create or edit a depot specification.
p4 depots
Display a list of depots known to the Perforce server.
p4 describe
Provides information about changelists and the changelists’ files.
p4 groups
List groups of users.
p4 group
Add or delete users from a group, or set the maxresults, maxscanrows, and timeout limits for the members of a group.
p4 have
List files and revisions that have been synced to the client workspace
p4 info
Display information about the current client and server.
p4 integrate
Open files for branching or merging.
p4 integrated
Show integrations that have been submitted.
p4 job
Create or edit a defect, enhancement request, or other job specification.
p4 jobs
List jobs known to the Perforce server.
p4 label
Create or edit a label specification and its view.
p4 labels
Display list of defined labels.
p4 lock
Lock an opened file against changelist submission.
p4 login
Log in to a Perforce server by obtaining a ticket.
p4 logout
Log out of a Perforce server by removing or invalidating a ticket.
p4 passwd
Change a user’s Perforce password on the server.
p4 rename
Renaming files under Perforce.
p4 resolve
Resolve conflicts between file revisions.
p4 revert
Discard changes made to open files.
p4 set
Set Perforce variables in the Windows registry.
p4 submit
Send changes made to open files to the depot.
p4 sync
Copy files from the depot into the workspace.
p4 tag
Tag files with a label.
p4 triggers
Edit a list of scripts to be run conditionally whenever changelists are submitted, forms are updated, or when integrating Perforce with external authentication mechanisms.
p4 user
Create or edit Perforce user specifications and preferences.
p4 users
Print a list of all known users of the current server.
p4 verify
Verify that the server archives are intact.
p4 workspace
Create or edit a client workspace specification and its view.
Tagged : / / / / /

Most User P4 Command Line – P4 Commands Reference

p4-command-line

p4 add

Open file(s) in a client workspace for addition to the depot.

Assigns a specific file type to a new file, overriding any settings in the typemap table

p4 add -t binary file.pdf

Opens all the files within the user’s current directory for add, and links these files to changelist 13.

p4 add -c 13 *

Opens all *.c files in the user’s ~/src directory for add; also opens the README file in the user’s current working

directory for add. These files are linked to the default changelist.

p4 add README ~/src/*.c

Opens a file named *.c for add.

p4 add -f *.c

p4 admin

Perform administrative operations on the server.

Stop the Perforce server

p4 admin stop

p4 change

Create or edit a changelist specification.

Create a new changelist.

p4 change

Edit previously submitted changelist 25. Administrator or superuser access is required.

p4 change -f 25

p4 changelists

List submitted and pending changelists.

p4 delete

Open file(s) in a client workspace for deletion from the depot.

Opens the file called README in the depot’s top level directory for deletion. The corresponding file within the client workspace is immediately deleted, but the file is not deleted from the depot until the default changelist is submitted.

p4 delete //depot/README

Opens file in the current client workspace for deletion. The file is immediately removed from the client orkspace, but won’t be deleted from the depot until changelist 40 is sent to the server with p4 submit.

p4 delete -c 40 file

p4 edit

Opens file(s) in a client workspace for edit.

Opens all files ending in .txt within the current directory’s doc subdirectory for edit. These files are linked to the default changelist; these files are stored as type text with keyword expansion.

p4 edit -t text+k doc/*.txt

p4 have

List files and revisions that have been synced to the client workspace

p4 info

Display information about the current client and server.

p4 integrate

Open files for branching or merging.

Branch or merge all files in //depot/dev/… to the corresponding files in

//depot/rel2/… If there is no corresponding file in //depot/rel2/…, this creates it.

p4 integ //depot/dev/… //depot/rel2/…

p4 job

Create or edit a defect, enhancement request, or other job specification.

p4 login

Log in to a Perforce server by obtaining a ticket.

p4 passwd

Change a user’s Perforce password on the server.

p4 resolve

Resolve conflicts between file revisions.

p4 revert

Discard changes made to open files.

Revert all open files to their pre-opened state.

p4 revert //depot/…

p4 submit

Send changes made to open files to the depot.

Submit the default changelist. The user’s revisions of the files in this changelist are stored in the depot.

p4 submit

Submit changelist 41.

p4 submit -c 41

p4 sync

Copy files from the depot into the workspace.

p4 sync

p4 sync file.c#4

p4 sync //depot/proj1/…@21

p4 user

Create or edit Perforce user specifications and preferences.

View the user specification of Perforce user joe.

p4 user joe

Edit the user specification for the current Perforce user.

p4 user

Delete the user specification for the Perforce user sammy.

p4 user -d sammy

P4CONFIG

Tagged : / / / / / / / / / / / /

“Cheat Sheet” of Perforce command-line | Perforce command-line Guide

perforce-command-line-cheatsheet

A way to remember data-mining commands
The following is a set of questions that will be used during the Perforce training to remind students which “data-mining” commands to use for specific situations. Perforce is a terrific tool, but it’s easy to get lost in the choices between “p4 files” and “p4 changes” and “p4 filelog” and so on. This list can help a great deal.

the question starts with…
the answer starts with…
Examples
“What are the filenames that…?” “p4 files….” p4 files //depot/…#have
p4 have
p4 files //depot/…
(which is the same as)
p4 files //depot/…#head
p4 files //depot/…@label
p4 files //depot/…@client
p4 files //depot/…@2001/02/12
p4 files //depot/…@1541
“What are the differences between the
workspace copy of XXX and the depot
copy of XXX?”
“p4 diff …” • p4 diff file.c
• p4 diff file.c#2
• p4 diff file.c#head
• p4 diff //… or “p4 diff”
• p4 diff –se
“What are the differences the depot copy
of ______ and the depot copy of ______?”
“p4 diff2 ….” • p4 diff2 file1.c file2.c
• p4 diff2 file1.c#1 file.c#2
• p4 diff2 dir1/… dir2/…
• p4 diff2 dir1/…@now dir1/…@2000/01/02
“Tell me everything about changelist #___.” “p4 describe” • p4 describe 1231
“What’s a list of changelists that….?” “p4 changes….” • p4 changes
(which is the same as)
p4 changes //…
• p4 changes file.c
• p4 changes –i file.c | grep 1255
• p4 changes //depot/…@label1,@label2

 

“Cheat Sheet” of Perforce command-line
The following list is a set of helpful commands that anyone can run, but that the person administering the Perforce codelines will
be using a lot. They’re included here for quick reference.

Function
Commands
Create a new workspace…
1. That’s modeled after the
“1.0dev” workspace – same
mappings
2. That’s the Perforce defaults,
Set the workspace name using “p4 set” or in the environment. Then run:
1. p4 client –t 1.0dev
2. p4 client
Retrieve a file as of
1. Now (head revision)
2. April 15, 2000
3. Label “xyz”
4. Changelist 123456
5. the revision that client
“jab.work” has retrieved
6. The revision you had before
accidently bashing your disk
Use “p4 sync” as follows:
1. p4 sync file.java
p4 sync file.java#head
p4 sync file.java@now
2. p4 sync file.java@2000/04/15
3. p4 sync file.java@xyz
4. p4 sync file.java@123456
5. p4 sync file.java@jab.work
6. p4 sync –f file.java#have
See “p4 help revisions” for more examples. Note that anywhere that “file.java” is used in these
examples, a full pathname (“c:\work\projects\file.java”) or depot name
(“//depot/rel_218/base/projects/file.java”) could be used.
Open a file for:
1. add
2. edit
3. delete
And then publish the change to others
.
Use “p4” with the appropriate verb:
• p4 add file.java
• p4 edit file.java
• p4 delete file.java
Then “p4 submit” to publish it
What have I changed in the files I
have opened for edit?
• p4 diff (for all opened files)
• p4 diff file1 file2 (for specific files)
Undo a checkout. If the file hasn’t been submitted yet:
• Use “p4 revert –a” to find all opened files that have no modifications – it’ll revert those.
• Use “p4 revert file.java” to revert an individual file.
• Use “p4 revert //…” to revert all files.
Remember that “p4 revert” is irreversible.
If the file has been submitted, you’ll need to open the file for edit and check in a prior revision.
Use very good change descriptions to say what you did and why.
Interrupt your work to edit a single
file and check it in, without any other
disruptions. (You’re hacking Java and
someone needs a “relnotes.txt”
updated ASAP to issue a release.)
Two ways:
1. Edit the file and submit only that file.
• p4 edit relnotes.txt
• do the modifications
• p4 submit relnotes.txt
2. Make a new changelist to manage just that change.
• p4 change
remove all the files in this change from the Files: section, it’ll create an empty
change.
• p4 edit –c XXX relnotes.txt
where XXX is the change number in the previous step
• p4 submit –c XXX
Publish your work to others “p4 submit”
Compress the data on the net
because you have a slow modem line
between your workspace and the
server.
Run “p4 client” for your workspace, and change the options from “nocompress” to “compress”.
(Read “p4 help client” for details.)
Get the list of…
1. All changelists applied to the
base codeline
2. … to the prodxyz codeline
3. … to the prodxyz codeline,
including those applied
originally to another codeline
and integrated into prodxyz
4. All revisions of file.java
Use “p4 changes” or “p4 filelog” as follows:
1. p4 changes //depot/eng/…
2. p4 changes //depot/eng/prodxyz/…
3. p4 changes –i //depot/eng/prodxyz/…
4. p4 filelog file.java
Push … from the base codeline
(“prodxyz”) to the 1.0.1 codeline
(“prodxyz-1.0.1”):
1. Push change #1232
2. From change #129 to #134
3. all changes in the base
codeline
Use “p4 integrate –b prodxyz-1.0.1” as the place to start, in each case:
1. p4 integ –b prodxyz-1.0.1 //…@=1232
2. p4 integ –b prodxyz-1.0.1 //…@129,@134
3. p4 integ –b prodxyz-1.0.1 (no additional args)
Note that this assumes that the named branch specification “prodxyz-1.0.1” has been created
by your project lead or administrator using “p4 branch”.
Push … from the prodxyz-1.0.1
codeline to the base (“prodxyz”)
codeline:
1. Push change #1235
2. From change #127 to #128
3. all changes in the base
Use “p4 integrate –b prodxyz-1.0.1” as the place to start, in each case:
1. p4 integ –b prodxyz-1.0.1 –r @=1235
2. p4 integ –b prodxyz-1.0.1 –r //…@127,@128
3. p4 integ –b prodxyz-1.0.1 –r (no additional args)
The “-r” reverses the order of source/target in that named branch specification.
Note that for the ‘selective integration’ cases, you’ll want to be VERY CAUTIOUS of ‘accept
theirs’.
Show the ‘diff’ between the
prodxyz-1.0.1 codeline and its
parent
“p4 diff2 –b prodxyz-1.0.1” (This works because “prodxyz” is the name of the branch
specification, not because “prodxyz” is part of “//depot/prodxyz/…”)
What branches do I have? If you use “p4 branch” to create branch specifications and use them consistently, then “p4
branches” provides this info.
How do I make a new codeline
named prodxyz-2.0?
There are several steps:
1. Make a named branch specification. Save it.
• “p4 prodxyz-2.0”
• if you want to exactly imitate another branch (e.g. prodxyz), use
“p4 branch –o prodxyz-1.0.1 > tmp” to capture the output, edit this temporary file
and replace the “1.0.1” references with “2.0”, then run “p4 branch –i < tmp”.
2. Run the “p4 integrate” command to populate this new codeline. Submit the change.
• p4 integrate –b prodxyz-2.0
or, if you want to push content as of a certain label (e.g. “xyz”) from the parent,
p4 integrate –b prodxyz-2.0 //…@xyz
• p4 submit
3. Send e-mail telling everyone about this codeline and what it’s used for.
Put everything onto a laptop, you’re
going to the beach and want to hack.
(This assumes that you won’t be
connected to a net while away.)
There are several steps:
1. Connect the laptop to the net.
2. Run “p4 sync” to populate the source onto the laptop.
3. Leave for the beach.
4. While editing, use “chmod” or “attrib” to make the files writeable. Make your changes.
5. Get back to work, reconnect to the net.
6. Run the following commands to tell you what’s updated and open them for
add/edit/delete:
• p4 diff –se | p4 –x – edit
• p4 diff –sd | p4 –x – delete
• find . –type f –print | p4 –x – add
Then inspect what’s opened (“p4 opened”) and what you’ve changed (“p4 diff”). Submit or
revert as appropriate.
Run a checkpoint “p4 admin checkpoint” – only an administrator can run this. (An administrator has “super”
permissions in the “p4 protect” data.)
Be sure to back up the checkpoint, the current journal, and each of the “depot” directories on
the server machine!
Change the security/permissions “p4 protect” – only an administrator can run this.
Also…
“p4 protects” – used in 2006.1 and later to TELL you your permissions .
Make a label It’s a two-step process:
1. Make the label using “p4 label xxx”
2. Populate it using “p4 labelsync –l xxx”
or if you have a specific list of files,
“p4 labelsync –l xxx file1 file2 …”.
Copy a label’s contents to another
label. Assume that the existing label
is “xxx” and the new label is to be
“abc”.
Again, a two-step process:
1. Make the label using “p4 label –t xxx abc”
2. Populate it using
“p4 labelsync –l abc //…@xxx”
Note that the second step is really identical to the second step in the previous question – we’re
just specifying a very specific list of revisions [of files] to include in the new label.
(Also…
In 2005.1 and later, “p4 tag” will make the label and apply it to a set of files.)

 

Tagged : / / / / / / / / / / / / / / / / / /