Resolve Conflicts in Models Using Three-Way Merge
You attempt to merge the changes on your Git™ branch into the main
branch. Conflicts occur.
Open Three-Way Merge Tool
Open the example to download the supporting files.
The repository has two conflicted model files. To make the changes that cause the conflicts yourself instead, see Make Changes and Merge Git Local Branch. If you have not yet determined the order in which you should resolve conflicted files, see Identify Order of Resolving Conflicts in Changeset.
To investigate and resolve conflicts using the Three-Way Merge Tool, in the Current Folder browser, right-click the models that have conflicts and select Source Control > View Conflicts.
Resolve the conflicts in the sldemo_mdlref_counter.slx
model before you resolve the conflicts in the sldemo_mdlref_basic.slx
model.
Resolve Conflicts in Changeset
The Three-Way Merge Tool opens three panes at the top that display the changes you made (Mine pane), the changes your colleague made (Theirs pane), and the common ancestor version (Base pane). Below, the tool automatically resolves differences when possible and opens a Target pane. The Target pane contains a copy of the Mine changes and automatic merges. Review the automerge choices, edit if desired, and decide how to resolve any remaining conflicts.
In this example, to resolve conflicts in your model files, resolve conflicts in the
sldemo_mdlref_counter.slx
model before you resolve the conflicts in the
sldemo_mdlref_basic.slx
model.
Resolve Conflicts in sldemo_mdlref_counter
To resolve conflicts in the sldemo_mdlref_counter.slx
model:
Examine the Three-Way Merge report for the
sldemo_mdlref_counter.slx
model.The summary table in the right bottom corner shows that three items in the report require your attention, two conflicts and one manual merge. The table also shows that no changes are filtered out that require your attention.
In the report, the tool colors conflicted items in red. For more information about colors and conflict classification in the report, see Three-Way Merge Tool.
Examine and resolve the first item that requires your attention. Click Next to navigate to the first item.
The tool selects the Name row under PortProperties. In the Target pane, the tool marks the item as requiring a manual merge . This action means that the tool cannot perform the change, and you must make the change in the Simulink® Editor. For more information about conflict classification, see Three-Way Merge Tool.
In this example, the report shows that your colleague changed the port name to
previous
, which conflicts with the name you added,previous_output
.The tool displays two models to the right of the report and highlights the differences in the Simulink Editor. In this example, the tool highlights the
Previous Output
block in yellow.By default, the tool opens the Theirs model on top and the Target model below. To configure the tool to open different models to the right of the report, in the toolstrip, in Highlight section, select one of the available configurations for Top Model and Bottom Model.
In the Simulink Editor, in the targetFile, change the name of the port from
previous
toprevious_output
, then save the model.After you resolve the conflict using the Simulink Editor, in the Target pane, select the check option to mark the item as resolved.
Examine and resolve the next item that requires your attention. Click Next to navigate to the next item. Alternatively, select the next item in the report.
Tip
Merge blocks before lines, and merge states and junctions before merging transitions. The merge tool then attempts to connect all lines to blocks. See Recommended Merge Order in Models.
The tool selects the Name row under Scope. In the Target pane, the tool marks the item as a conflict . This means that the tool can perform the change. The tool provides option buttons next to the item.
In this example, the report shows that your colleague changed the scope name to
Scope A
, which conflicts with the name you added,Scope
.The tool displays two models to the right of the report and highlights the differences in the Simulink Editor. In this example, the tool highlights the scope block in red with yellow around the edges.
Suppose you want to keep your change. In the Target pane, select the option button in the Mine column.
The tool automatically marks the item as resolved by switching the conflict icon to a green tick icon. The tool also colors the line in blue to indicate that the targetFile now contains the Mine change.
Examine and resolve the next item that requires your attention. Click Next to navigate to the next item.
The tool selects the Threshold row under Switch. In the Target pane, the tool marks the item as a conflict . This action means that the tool can perform the change. The tool provides option buttons next to the item.
In this example, the report shows that your colleague changed the switch Threshold value to
0.4
, a value that contradicts with your change.The tool displays two models to the right of the report and highlights the differences in the Simulink Editor. In this example, the tool highlights the switch block in red with yellow around the edges.
Suppose you want to restore the value in the Base file. In the Target pane, select the option button in the Base column.
The tool automatically marks the item as resolved by switching the conflict icon to a green tick icon. The tool also colors the line in orange to indicate that the targetFile now contains the Base change.
Examine the summary table. The table now shows that you resolved all the items that require attention.
To save the target file with all your merges and mark the conflicted file as resolved in the source control tool, click Accept and Close.
Resolve Conflicts in sldemo_mdlref_basic
To resolve conflicts in the sldemo_mdlref_basic.slx
model:
Examine the Three-Way Merge report for the
sldemo_mdlref_basic.slx
model. The summary table in the right bottom corner shows that one conflict in the report requires your attention.Examine and resolve the conflict. Click Next to navigate to the item that requires your attention.
The tool selects the Value row under C5. In the Target pane, the tool marks the item as a conflict . This action means that the tool can perform the change. The tool provides option buttons next to the item.
In this example, the report shows that your colleague changed the Constant block Value to
90
, a value that contradicts with your change.The tool displays two models to the right of the report and highlights the differences in the Simulink Editor. In this example, the tool highlights the constant block in red with yellow around the edges.
Suppose you want to keep your change. In the Target pane, select the option button in the Mine column.
The tool automatically marks the item as resolved by switching the conflict icon to a green tick icon. The tool also colors the line in blue to indicate that the targetFile now contains the Base change.
Examine the summary table. The table now shows that you resolved all the items that require attention.
To save the target file with all your merges and mark the conflicted file resolved in the source control tool, click Accept and Close.
Perform Last Checks
When you resolve the conflicts in both model files, the Git status now shows as Modified.
Before you commit the resolved model files to source control, perform a final review by comparing the merge changes against the current branch. You should always qualify merged models by verifying simulation results or running tests.
For an example on resolving conflicts using three-way merge in a MATLAB® projects under source control, see Resolve Conflicts in Project Using Simulink Three-Way Merge.
If you are using source control outside of MATLAB, you can customize external source control tools to use MATLAB comparison and merge tools. For instructions, see Customize External Source Control to Use MATLAB for Diff and Merge.