Main Content

Resolve Source Control Conflicts

Examining and Resolving Conflicts

If you and another user change the same file in different sandboxes or on different branches, a conflict message appears when you try to commit your modified files. Follow the procedure Resolve Conflicts to extract conflict markers if necessary, compare the differences causing the conflict, and resolve the conflict.

To resolve conflicts you can:

  • Use the Comparison Tool to merge changes between revisions.

  • Decide to overwrite one set of changes with the other.

  • Make changes manually by editing files.

For details on using the Comparison Tool to merge changes, see Merge Text Files.

After you are satisfied with the file that is marked conflicted, you can mark the conflict resolved and commit the file.

Resolve Conflicts

  1. Look for conflicted files in the Current Folder browser.

  2. Check the source control status column (SVN or Git) for files with a red warning symbol , which indicates a conflict.

  3. Right-click the conflicted file and select Source Control > View Conflicts to compare versions.

  4. Examine the conflict. A comparison report opens that shows the differences between the conflicted files.

    With SVN, the comparison shows the differences between the file and the version of the file in conflict.

    With Git™, the comparison shows the differences between the file on your branch and the branch you want to merge into.

  5. Use the Comparison Tool report to determine how to resolve the conflict.

    You can use the Comparison Tool to merge changes between revisions, as described in Merge Text Files.

  6. When you have resolved the changes and want to commit the version in your sandbox, in the Current Folder browser, right-click the file and select Source Control > Mark Conflict Resolved.

    With Git, the Branch status in the Source Control Details dialog box changes from MERGING to SAFE.

  7. Commit the modified files.

Merge Text Files

When comparing text files, you can merge changes from one file to the other. Merging changes is useful when resolving conflicts between different versions of files.

If you see conflict markers in a text comparison report like this:

<<<<<<< .mine
then extract the conflict markers before merging, as described in Extract Conflict Markers.

Tip

When comparing a file to another version in source control, by default the right file is the version in your sandbox and the left file is either a temporary copy of the previous version or another version causing a conflict (e.g., filename_theirs). You can swap the position of the files, so be sure to observe the file paths of the left and right file at the top of the comparison report. Merge differences from the temporary copy to the version in your sandbox to resolve conflicts.

  1. In the Comparison Tool report, select a difference in the report and click Merge. The selected difference is copied from the left file to the right file.

    Merged differences display gray row highlighting and a green merge arrow.

    The merged file name at the top of the report displays with an asterisk (filename.m*) to show you that the file contains unsaved changes.

  2. Click Save Merged File to save the file in your sandbox. To resolve conflicts, save the merged file over the conflicted file.

  3. If you want to inspect the files in the editor, click the line number links in the report.

    Note

    If you make any further changes in the editor, the comparison report does not update to reflect changes and report links can become incorrect.

  4. When you have resolved the changes mark them as conflict resolved. Right-click the file in the Current Folder browser and select Source Control > Mark Conflict Resolved.

Extract Conflict Markers

What Are Conflict Markers?

Source control tools can insert conflict markers in files that you have not registered as binary (e.g., text files). You can use MATLAB® to extract the conflict markers and compare the files causing the conflict. This process helps you to decide how to resolve the conflict.

Caution

Register files with source control tools to prevent them from inserting conflict markers and corrupting files. See Register Binary Files with SVN or Register Binary Files with Git. If your files already contains conflict markers, the MATLAB tools can help you to resolve the conflict.

Conflict markers have the following form:

<<<<<<<["mine" file descriptor]
["mine" file content]
=======
["theirs" file content]
<<<<<<<["theirs" file descriptor]

If you try to open a file containing conflict markers, the Conflict Markers Found dialog box opens. Follow the prompts to fix the file by extracting the conflict markers. After you extract the conflict markers, resolve the conflicts as described in Examining and Resolving Conflicts.

To view the conflict markers, in the Conflict Markers Found dialog box, click Load File. Do not try to load files, because MATLAB does not recognize conflict markers. Instead, click Fix File to extract the conflict markers.

MATLAB checks only conflicted files for conflict markers.

Extract Conflict Markers

When you open a conflicted file or select View Conflicts, MATLAB checks files for conflict markers and offers to extract the conflict markers. MATLAB checks only conflicted files for conflict markers.

However, some files that are not marked as conflicted can still contain conflict markers. This can happen if you or another user marked a conflict resolved without removing the conflict markers and then committed the file. If you see conflict markers in a file that is not marked conflicted, you can extract the conflict markers.

  1. In the Current Folder browser, right-click the file, and select Source Control > Extract Conflict Markers to File.

  2. In the Extract Conflict Markers to File dialog box, leave the default option to copy “mine” file version over the conflicted file. Leave the Compare extracted files check box selected. Click Extract.

  3. Use the Comparison Tool report as usual to continue to resolve the conflict.