Resolve Conflicts in Project Using Simulink Three-Way Merge - MATLAB & Simulink (original) (raw)

This example shows how to use the Simulink® Three-Way Merge tool to resolve conflicts in Simulink models in a project. You can view and merge the Simulink model differences in the resulting report.

Download an example project with conflicts by using the Copy Command button. The example project is under Git™ source control. When you attempt to merge the changes of a colleague on the main Git branch into your taskBranch, the operation results in conflicts.

To resolve the conflicts using the Three-Way Merge tool, you examine your local file (Mine, in this example, the taskBranch branch), the conflicting revision (Theirs, in this example, the main branch), and the common ancestor of these two files (Base).

The Merge tool automatically merges nonconflicted differences before opening the Three-Way Merge report. Follow these steps to review the automatic merge choices, apply your desired edits, and decide how to resolve any remaining differences. After you resolve the conflicts, commit the resolved model to source control.

In the Project panel, look for conflicted files. The slproject_f14 file shows a red warning icon in the source control column, which indicates a conflict.

To see a detailed report of the conflicts, right-click the slproject_f14 file and select Source Control > View Conflicts. Alternatively, in the Source Control panel, in the Modified Files section, right-click slproject_f14 file and select View Conflicts.

For easier interaction with projects under source control, group the Project and Source Control panels by dragging one panel icon next to another. If the Source Control icon is not in the sidebar, click the Open more panels button Open more panels icon and add it.

The MATLAB desktop shows the Project and Source Control panel with the project open on the left, the Project toolstrip on top, the Command Window in the middle, and the Project Issues panel on the right. The Source Control panel shows one conflicted file with a context menu. The mouse pointer points to the View Conflicts option.

View Changes

The Three-Way Merge tool shows the changes to the two Simulink models that cause this file conflict.

Three-Way Merge tool show a toolstrip on top, three panes (main, base, and taskBranch) in the middle, and the Target pane and the summary table on the bottom.

You can visually examine individual differences in the model files.

  1. To examine a difference, click a row in one of the trees. The Merge tool displays the change for each model in an editor, for example, the Simulink Editor or Configuration Parameters dialog box, to the right of the Three-Way Merge window.
  2. On the Merge tab, in the Highlight section, choose the models to display by clicking the Top Model or Bottom Model buttons.

Review Automatic Merges

The Merge tool automatically merges most nonconflicted differences before opening the Three-Way Merge report.

You can review and adjust all automatic merge choices. For example, examine the first change by clicking the PilotGain row. The Merge tool automatically merged this row by taking the change your colleague made in the main branch. You can adjust the automatic choices using the option buttons in the Target tree. Taking your change from the taskBranch deletes the PilotGain block your colleague added.

The model on the main branch with the PilotGain block highlighted on top and the targetFile with no PilotGain block below.

Resolve Conflicts

To resolve conflicts, follow these steps.

1. Use the Next button to navigate to the conflict. The StopTime parameter is conflicted because you and your colleague changed it. In the Target pane, by default, the tool selects the change from your branch taskBranch taskBranch icon.

2. To resolve the conflict using the default selection, mark the conflict as resolved. In the Target pane, click the conflict icon Conflict icon in the StopTime row and click Mark as Resolved. Alternatively, right-click the StopTime row and select Mark as Resolved.

If you want to keep the change from the main branch instead, select the option button in the main branch main branch icon column. When you make a selection, the tool automatically marks the item as resolved and updates the row color.

3. Check the summary table to verify you resolved all conflicts.

In this example, the summary table shows that you successfully resolved all conflicts.

Summary table shows that all changes have been resolved.

Tips:

Visible changes section shows two filters. The mouse pointer points to one of the filters.

Warning icon and a popout with a tip and a Mark as Resolved button.

Accept Changes

1. After you resolve all filtered and unfiltered changes, click Accept & Close. The merge tool closes the report and the models, accepts the merge result in targetFile, and marks the conflict as resolved in the source control tool.

2. Before you commit the resolved model file to source control, perform a final review by comparing the merge changes against the current branch.

In the Project panel, right-click the model and select Source Control > View Changes.

Tips:

When you click Accept & Close, the tool prompts you if you still have conflicts to resolve. If you click Continue, the tool selects the Mine change, in this example taskBranch, to resolve all unresolved conflicts.

Save Result dialog box with Continue and Cancel buttons.

See Also

Tools

Topics