You can work on your Perforce workspace files when disconnected from the Perforce server. However, you will not have any access to Perforce server functions when working disconnected. Also, any changes you make to your versioned files while working offline will make your workspace inconsistent with the Perforce Server metadata. When you reconnect to the Perforce Server, you must reconcile your offline changes.
NOTE: By default, Perforce keeps all unopened files in the workspace as read only. If you need to work offline you will need to use operating system commands to make the files writeable before editing them!
In Linux make a file writeable with
"chmod +w <filename>" in Windows use "
attrib -r <filename>" .
It is also possible to keep workspace files always writable by editing your client workspace and setting the 'allwrite' option. See 'p4 help client' for details.
The Perforce Server tracks the files you have in your client workspace, including which files you have opened for adding, deleting, editing, or integrating. If you create, remove, or modify workspace files without using a Perforce client (for example, by using operating system commands such as move or del), the Perforce Server will not be aware of the changes and your client workspace gets out of sync with the server. This workspace inconsistency can occur when you do some work offline, for example, when you use your laptop on the train, or when you use an application development environment that does not work directly with Perforce for file management. In order to ensure that the Perforce Server properly track workspace file state, you need to reconcile your offline work when reconnecting to the Perforce Server.
Reconciling Offline Work
This section describes how to reconcile your Perforce client information with workspace changes made outside of the Perforce system, and how to build a changelist when you later reconnect to the server. This changelist, which describes the differences between your modified workspace and the files in the Perforce depot, can then be submitted.
The three most common types of workspace changes that can go into a reconciled changelist are:
- files deleted
- files changed
- new files added
Reconcile Offline Work using P4V
- After connecting to the server in P4V, click the Workspace tab in the lower left hand corner.
- Select the folder you would like to find added, edited, or deleted files. Perforce compares this folder with your client workspace's "have list"; that is, what files you last had.
- Context-click on the folder and select "Reconcile offline work". Note the "Folder Diff" pane appears.
- Click the cyan blue arrow icons at the top to scroll through file differences, and note your Reconcile Options in the Details tab in the lower pane. The darkest line shows you what file or directory File Diff is focused on.
Note that you can make multiple selections using the control and shift keys. Close this screen when you are finished. Select View -> Pending Changelists, and see the right pane to see your changes. Submit these changes when you are ready.
- A purple highlight indicates a file has been modified.
Select this file and context-click, select "Check Out" if you want to edit or check in your changes to Perforce.
- A yellow (or brown) highlight indicates a file is new.
Select this file and context-click, select "Mark for Add" to add the file to Perforce, and the file is removed from view.
- A strikethrough indicates the file was deleted from your workspace.
Select this file and context-click, select "Mark for Delete" if you want to delete this file from Perforce.
Reconcile using the P4 Command Line
Using the "p4 reconcile" command (2012.1 and later)
Starting with server release 2012.1 the p4 reconcile command is available.
'p4 reconcile' allows users to reconcile a client with offline work. The command either previews or opens files in a pending changelist that will bring the client up to date with changes made to the workspace outside of Perforce.This Blog Entry
explains how to use p4 status
and p4 reconcile
to to update a server with offline work.
Using the P4 Command Line client (before 2012.1)
In the following example you are using a client named "myclient", whose workspace root is "/testclient" (UNIX) or "c:\testclient" (Windows).
- First, open for "delete" any old files no longer present:
p4 diff -sd //myclient/... | p4 -x - delete
p4 diff -sd returns the names of depot files with no corresponding workspace file. All files you removed from your workspace are now opened for delete.
Next, open for edit any files that have changed:
p4 diff -se //myclient/... | p4 -x - edit
p4 diff -se returns the names of depot files whose corresponding client file differs in any way from the clients #have revision.
Next, find the new files and open them for add:
find . -type f -print | p4 -x - add
Note that the above command does not add symlinks. See Adding a Directory Tree for details.
dir /s /b /a-d | p4 -x - add
For an explanation of the dir flags, see Windows help. For example, in Windows XP, you go to Start -> Help and Support, and look up "dir".
files -f -q -r -s | p4 -x - add
The above commands attempts to add every file in the workspace path as a new depot file. For any file that already exists in the depot you get a message "... - can't add existing file," which is harmless. All new files you created in your workspace are now opened for add.
For more information on working disconnected, see Chapter 4: Managing Files and Changelists in the Perforce User's Guide.