Perforce global options allow you to give additional information to a Perforce client application to provide or override your existing Perforce settings on an "as needed" basis, such as your user name, the server port, workspace, and so forth.
Running a command as another user, workspace and server
Global options can be used when you want to simulate a command as run by another user. Here is a typical "p4 files" command with these three global values explicitly included:
p4 -p p4-server:1666 -u Bob -c Bobs-Wspace files -m 10 //depot/...
This command is requesting a list of files from the Perforce server, limiting the output to the first ten files. Breaking down the flags and arguments prior to the "files" command:
"-p p4-server:1666" - Connect to the machine called "p4-server" on port "1666";
"-u Bob" - Using user name "Bob";
"-c Bobs-Wspace" - Using the workspace "Bobs-Wspace".
Once the connection is made, your request is passed to the server, returning the results based on the global options provided.
Overriding the Host Name
By default workspaces are created with the current host (the network name of machine on which you created the workspace) in the workspace specification "Host" field. If you need information related to that workspace but are working on a different host, or if the host-name of the machine you are working on has changed, commands that require the workspace will produce an error similar to:
Client 'Bobs-Workspace' can only be used from host 'BOBS-MACHINE'.
To avoid this error you would use the "-H" global option to specify a specific host. The "Reverting Another User's Files
" knowledge base article has an example of this usage:
p4 -u Bob -c Bobs-Wspace -p p4-server:1666 -H BOBS-MACHINE revert -k //depot/...
Here the workspace "Bobs-Wspace" was created and used on host "BOBS-MACHINE". A super user needed to revert those files. While a Perforce administrator could edit the workspace specification to use a new host name, this would cause problems if the original workspace was still in use if the administrator forgot to restore the old name. Using the "-H" flag avoids changing the original workspace, and the files are reverted.
Note: If you find you are frequently using global options to issue client commands, you may want to consider using a P4CONFIG file instead. This will allow you to create a set of directories, each with its own configuration file, to run command as a given set of parameters without typing out the options for every command. As most global options have an equivalent environment variable, this can provide users with a very flexible way to change settings as needed. For more information about P4CONFIG files, see the entry for this variable in the Perforce Command Reference.
Note: Some commands, such as sync and edit, require access to the workspace root located on the user's machine. In other words, the command:
p4 -c Bobs-Wspace sync //...
Will likely produce an error regarding the workspace specification, usually the workspace root not being present. While you can avoid workspace errors by telling the server to not transfer the files by adding the sync command "-k" flag, this is not usually useful and can potentially cause serious problems by updating the user's "have" list to files not actually in that user's workspace.
A complete list of the global options available can be found in the command-line help:
p4 help usage
Or in the Perforce Command Reference.