Main Content

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.

slcomparisons.examples.simulinkThreeWayMerge;
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 master Git branch into yourTaskBranch. 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. Theslproject_f14file shows a red warning symbol in the Git column, which indicates a conflict.

1. To see a detailed report of the conflicts, right-click theslproject_f14file and selectView Conflicts.

View Changes

The Three-Way Merge tool shows the changes to the two Simulink designs that have caused this file conflict.

  • TheTheirs,BaseandMinetrees show the differences between the conflicting revision, your revision, and the base ancestor of these files.

  • TheTargettree 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 theMergetab, in theHighlightsection, choose the models to display with theTop Modelor底模型buttons.

Review Automatic Merges

合并了l automatically merges most nonconflicted differences.

4. Examine the first change at the top of theTheirstree by clicking the row called飞行员Gain. This node has been merged automatically and you can adjust the automatic choices using the buttons in theTargettree. If you want, review the other automatic merge choices.

Resolve Conflicts

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 theTargetpane, look for warnings in the conflict column.

Manual merge: Some differences must be merged manually in Simulink or ignored. In theTargetpane, these items are indicated by a pencil icon in the conflict column.

5. Select theStickCommand_radrow. This difference requires a manual merge, indicated by a pencil icon in the conflict column.

Resolve the line change difference in thetargetFileby renaming the line connected to the output of the block named飞行员in the Simulink Editor fromStickCommand_radto飞行员Output.

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 theNexttoolstrip button to review and resolve the changes until you reach a conflict. ThisStopTimeparameter has been changed by both users and is conflicted. Resolve the conflict using theMinechange. Select the button next toStopTimein the mine column in theTargetpane.

Change Filters

By default, the report hides all nonfunctional changes, such as the repositioning of items.

7. On theMergetab, in theFiltersection, turn on and off filters to explore the different changes between these designs.

Accept Changes

8. After you resolve all filtered and unfiltered changes, clickAccept & Close. The merge tool closes the report and the models, accepts the merge result in thetargetFile, and marks the conflict as resolved in the source control tool. You can now commit changes to source control and continue your work.

Further Information

Compare Simulink Models

Source Control in Projects

Resolve Conflicts

Compare Revisions

自定义外部源控制使用MATLAB for Diff and Merge

Related Examples

Compare and Merge Simulink Models

Compare and Merge Simulink Models Containing Stateflow