Resolve Conflicts with Simulink Three-Way Merge
This example shows you how to use Simulink® Three-Way Merge to resolve conflicts in Simulink models. You can view and merge the Simulink model differences in the resulting report.
Set up the Example Project
Create and open a working copy of the example project. MATLAB® copies the files to an example folder so that you can edit them.
Building with 'MinGW64 Compiler (C)'. MEX completed successfully.
Simulink Model Changes and Conflicts
The example project is under Git™ source control. You attempt to merge the changes of another user on the main Git branch into your
TaskBranch. This operation results in conflicts.
To resolve the conflicts using the Three-Way Model Merge tool, this example shows how to examine your local file (Mine), the conflicting revision (Theirs) and the common ancestor of these two files (Base).
Theirs: Another user updated the pilot model subsystem to use an explicit gain block for the amplitude of the pilot's input commands. He also updated the Simulation stop time.
Mine: You changed some configuration settings for the pilot model subsystem.
The Merge tool automatically merges nonconflicted differences. Follow the steps below to review the automerge choices, edit if desired, and decide how to resolve any remaining differences. After resolving the conflicts, commit the resolved model to source control.
Open Simulink Three-Way Merge
Look for conflicted files in the project files view. The
slproject_f14 file shows a red warning symbol in the Git column, which indicates a conflict.
1. 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 have caused 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 that you will merge changes into. This is a temporary file and will be copied into the project when you choose to accept the merge result.
2. 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.
3. On the Merge tab, in the Highlight section, choose the models to display with the Top Model or Bottom Model buttons.
Review Automatic Merges
The merge tool automatically merges most nonconflicted differences.
4. Examine the first change at the top of the Theirs tree by clicking the row called
PilotGain. This node has been merged automatically and you can adjust the automatic choices using the buttons in the Target tree. If you want, review the other automatic merge choices.
There are two types of difference that require user action.
Conflict: The merge tool cannot automatically resolve these differences and you need to choose which design you want in the target file. In the Target pane, look for warnings in the conflict column .
Manual merge: Some differences must be merged manually in Simulink or ignored. In the Target pane, these items are indicated by a pencil icon in the conflict column .
5. Select the
StickCommand_rad row. This difference requires a manual merge, indicated by a pencil icon in the conflict column .
Resolve the line change difference in the
targetFile by renaming the line connected to the output of the block named
Pilot in the Simulink Editor from
After resolving the difference save the changes in the Editor, and mark the change resolved using the manual merge control in the Conflicts column.
The merge report does not update to show any changes you make in the Editor.
6. Use the Next toolstrip button to review and resolve the changes until you reach a conflict. This
StopTime parameter has been changed by both users and is conflicted. Resolve the conflict using the Mine change. Select the button next to
StopTime in the mine column in the Target pane.
By default, the report hides all nonfunctional changes, such as the repositioning of items.
7. On the Merge tab, in the Filter section, turn on and off filters to explore the different changes between these designs.
8. 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 the
targetFile, and marks the conflict as resolved in the source control tool. You can now commit changes to source control and continue your work.