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. When you attempt to merge the changes of another user on the main Git branch into your
the operation results in conflicts.
To resolve the conflicts using the Three-Way 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 input commands of the pilot. He 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. Follow these steps 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.
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 file is temporary and will be copied into the project when you choose to accept the merge result.
1. 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.
2. 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.
Examine the first change at the top of the Theirs tree by clicking the row called
PilotGain. The Merge tool automatically merged this node. 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 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 .
1. Select the
StickCommand_rad row. This difference requires a manual merge, indicated by a pencil icon in the conflict column .
2. To resolve the line change difference in the
targetFile, in the Simulink Editor, change the name of the line connected to the output of the block named
After resolving the difference, save the changes in the Simulink Editor and mark the change resolved using the manual merge icon in the conflict column .
The merge report does not update to show any changes you make in the Simulink Editor.
3. On the toolstrip, click Next 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. In the Target pane, in the Mine column , select the button next to
By default, the report hides all nonfunctional changes, such as the repositioning of items.
On the Merge tab, in the Filter section, turn filters on and off to explore the different changes between these designs.
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.
Customize External Source Control to Use MATLAB for Diff and Merge
Compare and Merge Simulink Models