Resolve Conflicts with Simulink Three-Way Merge
This example shows how to use the Simulink® Three-Way Merge tool to resolve conflicts in Simulink models. You can view and merge the Simulink model differences in the resulting report.
For a visual walkthrough of the example, watch the video.
Simulink Model Changes and Conflicts
The 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), the conflicting revision (Theirs), and the common ancestor of these two files (Base).
Theirs - A colleague updated the pilot model subsystem to use an explicit Gain block for the amplitude of the input commands of the pilot. The colleague also updated the Simulation stop time parameter.
Mine - You changed some configuration settings for the pilot model subsystem.
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.
Open Simulink Three-Way Merge
In the project Files view, look for conflicted files. The
slproject_f14 file shows a red warning icon in the Git column, which indicates a conflict.
To see a detailed report of the conflicts, right-click the
slproject_f14 file and select View Conflicts.
The Three-Way Merge tool shows the changes to the two Simulink designs that cause this file conflict.
The Theirs, Base, and Mine trees show the differences between the conflicting revision, your revision, and the base ancestor of these files.
The Target tree shows the file into which you merge changes. The tool copies this temporary file into the project when you choose to accept the merge result.
The summary table in the bottom right corner shows that the merge tool automatically resolved four nonconflicting differences. The table also shows that you must resolve the two remaining changes.
To resolve the remaining changes, follow these steps.
Examine a difference by clicking 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.
On the Merge tab, in the Highlight section, choose the models to display by clicking Top Model or Bottom Model.
Review Automatic Merges
The Merge tool automatically merges most nonconflicted differences before opening the Three-Way Merge report.
Examine the first change at the top of the Theirs tree by clicking the
PilotGain row. The Merge tool automatically merged this row. You can adjust the automatic choices using the buttons in the Target tree. You can review and adjust all automatic merge choices.
Two types of differences require you to take action.
Conflict - The merge tool cannot automatically resolve these differences. You must choose which design to keep in the target file. In the Target pane, in the conflict column , a warning icon indicates these differences.
Manual merge - Some differences require you to manually make a change in Simulink. In the Target pane, in the conflict column , a pencil icon indicates these differences.
To resolve conflicts, follow these steps.
1. Use the Next button to navigate to the first conflict.
StickCommand_rad difference requires a manual merge, indicated by a pencil icon in the conflict column .
2. To resolve the line change difference in
targetFile, in the Simulink Editor, change the name of the line connected to the output of the
Pilot block from
After you resolve the difference, save the changes in the Simulink Editor and mark the change resolved using the manual merge menu .
When you make changes in the Simulink Editor, the merge report does not instantaneously reflect your changes.
3. On the toolstrip, click Next to review the next conflict. The
StopTime parameter is conflicted because you and your colleague changed it. Resolve the conflict using the Mine change. In the Target pane, in the Mine column , select the button next to
4. Check the summary table to verify you resolved all conflicts.
In this example, the summary table shows that you successfully resolved all conflicts.
If you resolved all conflicts in the current view but the summary table title is Resolve remaining x changes, disable the filters to view and resolve the remaining conflicts. On the Merge tab, in the Filter section, turn the filters off.
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 Files view, right-click the model and select Compare > Compare to Ancestor.