Previous Table of Contents Index Next
Perforce 2012.1: Command Reference



p4 sync
Synopsis
Copy files from the depot into the workspace.
Syntax
p4 [g-opts] sync [-f] [-L] [-k] [-n] [-q] [-m max] [file[revRange]...]
p4 [g-opts] sync [-L] [-n] [-q] [-s] [-m max] [file[revRange]...]
p4 [g-opts] sync [-L] [-n] [-p] [-q] [-m max] [file[revRange]...]
Description
p4 sync brings the client workspace into sync with the depot by copying files matching its file pattern arguments from the depot to the client workspace. When no file patterns are specified on the command line, p4 sync copies a particular depot file only if it meets all of the following criteria:
In new, empty, workspaces, all depot files meet the last two criteria, so all the files visible through the workspace view are copied into the user's workspace.
If file patterns are specified on the command line, only those files that match the file patterns and that meet the above criteria are copied.
If the file pattern contains a revision specifier, the specified revision is copied into the client workspace.
If the file argument includes a revision range, only files selected by the revision range are updated, and the highest revision in the range is used. Files that are no longer in the workspace view are not affected if the file argument includes a revision range.
The newly synced files are not available for editing until opened with p4 edit or p4 delete. Newly synced files are read-only; p4 edit and p4 delete make the files writable. Under normal circumstances, do not use your operating system's commands to make the files writable; instead, use Perforce to do this for you.
Options
Force the sync. Perforce performs the sync even if the client workspace already has the file at the specified revision. If the file is writable, it is overwritten.
This flag does not affect open files, but it does override the noclobber client option.
Keep existing workspace files; update the have list without updating the client workspace. Use p4 sync -k only when you need to update the have list to match the actual state of the client workspace.
For scripting purposes, perform the sync on a list of valid file arguments in full depot syntax with a valid revision number.
Sync only the first max files specified.
Populate a client workspace, but do not update the have list. Any file that is already synced or opened is bypassed with a warning message.
This option is typically used for workspaces used in processes (such as certain build or publication environments) where there is no need to track the state of the workspace after it has first been synced.
Quiet operation: suppress normal output messages. Messages regarding errors or exceptional conditions are not suppressed.
Safe sync: Compare the content in your client workspace against what was last synced. If the file was modified outside of Perforce control, an error message is displayed and the file is not overwritten.
Usage Notes
Can File Arguments Use
Revision Specifier?
If the client view has changed since the last sync, the next sync removes from the client workspace those files that are no longer visible through the client view (unless a revision range is used), and copies into the client workspace those depot files that were not previously visible.
By default, any empty directories in the client view are cleared of files, but the directories themselves are not deleted. To remove empty directories upon syncing, turn on the rmdir option in the p4 client form.
If a user has made certain files writable by using OS commands outside of Perforce's control, p4 sync will not normally overwrite those files. If the clobber option in the p4 client form has been turned on, however, these files will be overwritten.
You can prevent this behavior (at a minor cost in performance) by using the -s "safe sync" option. Even if the clobber option is set, p4 sync -s will not overwrite files modified outside of Perforce control.
p4 flush is an alias for p4 sync -k. All of the warnings that apply to p4 flush also apply to p4 sync -k.
The -m max flag is useful when combined with the -n flag for efficient scripting. For example, a command like p4 sync -n -m 1 does not sync any files, but displays only one line of output if there are any files to be synced, or a message indicating that the workspace is up to date. Without the -m 1 option, the output could conceivably be thousands of lines long, all of which would be discarded.
The -L flag is intended for use by scripts or automated reporting processes. File arguments must be in full depot syntax, and have a valid revision number. File specifications that do not meet these these requirements are silently ignored.
If your client workspace is dynamically-generated because your client workspace's Stream: field is set to a valid stream, and you have also set the StreamAtChange: field to point to a specified changelist number, p4 sync, when called with no arguments, will sync your workspace to the revisions of files available as of that changelist, using the client workspace that corresponds to the corresponding stream specification at that point in time.
Examples
Copy the latest revision of all files from the depot to the client workspace, as mapped through the client view.
If the file is already open in the client workspace, or if the latest revision of the file exists in the client workspace, it is not copied.
Copy the fourth revision of file.c to the client workspace, with the same exceptions as in the example above.
Copy all the files under the //depot/proj1 directory from the depot to the client workspace, as mapped through the client view.
Don't copy the latest revision; use the revision of the file in the depot after changelist 21 was submitted.
p4 sync @labelname
If labelname is a label created with p4 label, and populated with p4 labelsync, bring the workspace into sync with the files and revision levels specified in labelname.
Files listed in labelname, but not in the workspace view, are not copied into the workspace.
Files not listed in labelname are deleted from the workspace. (That is, @labelname is assumed to apply to all revisions up to, and including, the revisions specified in labelname. This includes the nonexistent revision of the unlisted files.)
p4 sync @labelname,@labelname
Bring the workspace into sync with a label as with p4 sync @labelname, but preserve unlabeled files in the workspace.
(The revision range @labelname,@labelname applies only to the revisions specified in the label name itself, and excludes the nonexistent revision of the unlisted files.)
Bring the workspace into sync with the depot as of midnight, June 24, 2001. (That is, include all changes made during June 23.)
Sync a filename containing a Perforce wildcard by using the ASCII expression of the character's hexadecimal value. In this case, the file in the client workspace is [email protected].
Sync to the nonexistent revision of file.c; the file is deleted from the workspace.
Sync to the nonexistent revision of all files; all files in the workspace (that are under Perforce control) are removed.
Related Commands


Previous Table of Contents Index Next

Perforce 2012.1: Command Reference
Copyright 1999-2012 Perforce Software.