In settings where multiple users are working on the same set of files, conflicts can occur. Perforce enables your team to work on the same files simultaneously and resolve any conflicts that arise. For example, conflicts occur if two users change the same file (the primary concern in team settings) or you edit a previous revision of a file rather than the head revision.
When you attempt to submit a file that conflicts with the head revision in the depot, Perforce requires you to resolve the conflict. Merging changes from a development branch to a release branch is another typical task that requires you to resolve files.
To prevent conflicts, Perforce enables you to lock files when they are edited. However, locking can restrict team development. Your team needs to choose the strategy that maximizes file availability while minimizing conflicts. For details, refer to
Locking files.
If Perforce accepts Gale's version into the depot, her changes will overwrite Bruno's changes. To prevent Bruno's changes from being lost, the Perforce server rejects the changelist and schedules the conflicting file to be resolved. If you know of file conflicts in advance and want to schedule a file for resolution, sync it. Perforce detects the conflicts and schedules the file for resolution.
To resolve a file conflict, you determine the contents of the files you intend to submit by issuing the
p4 resolve command and choosing the desired method of resolution for each file. After you resolve conflicts, you submit the changelist containing the files.
1.
|
Sync the files (for example p4 sync //depot/dev/main/jam/...). Perforce detects any conflicts and schedules the conflicting files for resolve.
|
The p4 resolve command uses the following terms during the merge process.
To specify how a conflict is to be resolved, you issue the p4 resolve command, which displays a dialog for each file scheduled for resolve. The dialog describes the differences between the file you changed and the conflicting revision. For example:
The differences between each pair of files are summarized by p4 resolve. Groups of lines (chunks) in the
yours,
theirs, and
base files can differ in various ways. Chunks can be:
•
|
Diffs: different between two of the three files: yours, theirs, or base
|
To reresolve a resolved but unsubmitted file, specify the -f flag when you issue the
p4 resolve command. You cannot reresolve a file after you submit it.
|
|
|
|
|
•
|
If theirs is identical to base, accept yours.
|
•
|
If yours is identical to base, accept theirs.
|
•
|
If yours and theirs are different from base, and there are no conflicts between yours and theirs; accept merge.
|
|
|
|
If you edited the merge file (by selecting e from the p4 resolve dialog), accept the edited version into the client workspace. The version in the client workspace is overwritten.
|
|
|
Accept merge into the client workspace as the resolved revision. The version in the client workspace is overwritten.
|
|
|
Accept theirs into the client workspace as the resolved revision. The version in the client workspace is overwritten.
|
|
|
Accept yours into the client workspace as the resolved revision, ignoring changes that might have been made in theirs.
|
Accepting yours,
theirs,
edit, or
merge overwrites changes, and the generated merge file might not be precisely what you want to submit to the depot. The most precise way to ensure that you submit only the desired changes is to use a merge program or edit the merge file.
To resolve files by editing the merge file, choose the e option. Perforce launches your default text editor, displaying the merge file. In the merge file, diffs and conflicts appear in the following format:
>>>> ORIGINAL file# n (text from the original version)
==== THEIR file# m (text from their file)
==== YOURS file (text from your file)
<<<<
|
To locate conflicts and differences, look for the difference marker ">>>>" and edit that portion of the text. Examine the changes made to
theirs to make sure that they are compatible with your changes. Make sure you remove all conflict markers before saving. After you make the desired changes, save the file. At the
p4 resolve prompt, choose
ay.
By default, only the conflicts between the yours and
theirs files are marked. To generate difference markers for all differences, specify the
-v flag when you issue the
p4 resolve command.
A merge program displays the differences between yours, theirs, and the base file, and enables you to select and edit changes to produce the desired result file. To configure a merge program, set
P4MERGE to the desired program. To use the merge program during a resolve, choose the
m option. For details about using a specific merge program, consult its online help.
The p4 resolve command offers the following options.
|
|
|
|
|
|
|
|
•
|
If theirs is identical to base, accept yours.
|
•
|
If yours is identical to base, accept theirs.
|
•
|
If yours and theirs are different from base, and there are no conflicts between yours and theirs; accept merge.
|
|
|
|
If you edited the merge file (by selecting e from the p4 resolve dialog), accept the edited version into the client workspace. The version in the client workspace is overwritten.
|
|
|
Accept merge into the client workspace as the resolved revision. The version in the client workspace is overwritten.
|
|
|
Accept theirs into the client workspace as the resolved revision. The version in the client workspace is overwritten.
|
|
|
Accept yours into the client workspace as the resolved revision, ignoring changes that might have been made in theirs.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Edit the revision in the depot that the client revision conflicts with (usually the head revision). This edit is read-only.
|
|
|
|
|
|
Invoke the command P4MERGE base theirs yours merge. To use this option, you must set P4MERGE to the name of a third-party program that merges the first three files and writes the fourth as a result.
|
|
|
|
|
The merge file is generated by the Perforce server, but the differences displayed by dy, dt, dm, and d are generated by the client machine's diff program. To configure another diff program to be launched when you choose a d option during a resolve, set P4DIFF. For more details, see Diffing files.
|
Jam/MR (formerly "jam - make(1) redux") /+\ >>>> ORIGINAL README#26 +\ Copyright 1993, 1997 Christopher Seiwald. ==== THEIRS README#27 +\ Copyright 1993, 1997, 2004 Christopher Seiwald. ==== YOURS README +\ Copyright 1993, 1997, 2005 Christopher Seiwald. <<<< \+/
|
When a version of the file is accepted during a resolve, the file in the workspace is overwritten, and the new client file must still be submitted to the depot. New conflicts can occur if new versions of a file are submitted after you resolve but before you submit the resolved files. This problem can be prevented by locking the file before you perform the resolve. For details, see
Locking files.
The following p4 resolve flags enable you to resolve directly instead of interactively. When you specify one of these flags in the
p4 resolve command, files are resolved as described in the following table.
|
|
|
|
|
|
|
Accept theirs. Use this option with caution, because the file revision in your client workspace is overwritten with the head revision from the depot, and you cannot recover your changes.
|
|
•
|
If theirs is identical to base, accept yours.
|
•
|
If yours is identical to base, accept theirs.
|
•
|
If yours and theirs are different from base, and there are no conflicts between yours and theirs, accept merge.
|
|
|
Accept the recommended file revision, even if conflicts remain. If this option is used, edit the resulting file in the workspace to remove any difference markers.
|
|
•
|
If theirs is identical to base, accept yours.
|
•
|
If yours is identical to base, accept theirs.
|
|
He then types p4 resolve -am and the merge files for all scheduled resolves are generated, and those merge files that contain no line set conflicts are written to his client workspace. He'll still need to manually resolve any conflicting files, but the amount of work he needs to do is substantially reduced.
After you open a file, you can lock it to prevent other users from submitting it before you do. The benefit of locking a file is that conflicts are prevented, but when you lock a file, you might prevent other team members from proceeding with their work on that file.
Although exclusive locking prevents concurrent development, for some file types (binary files), merging and resolving are not meaningful, so you can prevent conflicts by preventing multiple users from working on the file simultaneously.
Your Perforce administrator can use the p4 typemap command to ensure that all files of a specified type (for instance,
//depot/.../*.gif for all
.gif files) can only be opened by one user at a time. See the
Perforce Command Reference for details.
The difference between p4 lock and
+l is that
p4 lock allows anyone to open a file for edit, but only the person who locked the file can submit it. By contrast, a file of type
+l prevents more than one user from opening the file.
Copyright 2005-2009 Perforce Software.