You can work on your 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.
Your client workspace is kept in sync when Perforce not only knows which files you have in your workspace, but which files you have opened for adding, deleting, or editing. If you create, remove, or modify workspace files without Perforce's knowledge, your workspace gets out of sync. Typically this happens 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.
This article describes how to reconcile your Perforce client information with workspace changes made outside of the 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.
There are three types of workspace changes that can go in the changelist:
- files deleted
- files changed
- new files added
Renamed files are also covered in a separate section below.
Add, Edit, or Delete through P4V
This is accomplished through 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.
- 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.
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.
Reconcile through the 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.
Add, Edit, and Delete Through the Command Line (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.
Add, Edit, or Delete through P4Win
Users of P4Win can employ the built-in Check Consistency command located on the P4Win File ->More menu.
When you complete these steps, you have a changelist that contains the files you created, removed, modified or renamed. After you examine the changelist to make sure it does not refer to any extraneous files, you can submit this changelist.
If you renamed any files, decide if you want to add them or use p4 integrate to branch them.
Renaming files offline is not recommended because there is no direct way for Perforce to detect if a file was renamed or simply deleted. The rename operation in Perforce is a two step process: an integrate followed by a delete. If you did rename a file offline, then Step #1 in the command line example above detects the renamed file as a newly added file, and Step #2 detects the old renamed file as a deleted file and opens the old file name for delete. For files renamed offline, the delete operation in Step #2 is correct, but the add operation in Step #1 is not. Instead of adding the renamed files (as in Step #1), the proper thing to do with such files is to branch the old file name into the new file name. Although adding the renamed file as a new file does work, using the integrate operation is better because it creates a link between the old and new file names that preserves the change history across the rename.
If you see a newly renamed file appear in your changelist marked for add as a result of Step #1 from the command line example above, it is possible to change the add to an integrate. However, doing so requires that you perform a p4 revert operation first. If you made any content changes to the newly renamed file, those changes might be lost as a result of the revert. For example, if you renamed file "abc.c" to "xyz.c" while working offline, after performing steps 1 through 3 from the command line example above, you could then correct the errant add operation as follows:
p4 revert xyz.c
p4 integrate abc.c xyz.c
Again, note that if you made changes to the file "xyz.c" after renaming it from "abc.c", the changes to "xyz.c" are lost because of the need to revert. An alternative approach which avoids the possibility of losing your local changes is to prevent the integrate from overwriting your local files. The commands required are an extension of those listed above:
p4 revert xyz.c
p4 integrate -v abc.c xyz.c
p4 edit xyz.c
p4 delete abc.c
p4 flush xyz.c
Reopening the file for edit tells the server to take the local file contents rather than perform a lazy copy and running the flush command updates the clients have list to reflect the changes made.
For more information on working disconnected, see Chapter 4: Managing Files and Changelists in the Perforce User's Guide.