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.

setupResolveConflictsExample;
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 yourTaskBranch,theoperation 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 explicitGainblock 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. Theslproject_f14file shows a red warning symbol in the Git column, which indicates a conflict.

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 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 theMergetab, in theHighlightsection, choose the models to display by clickingTop ModelorBottom Model.

Review Automatic Merges

The merge tool automatically merges most nonconflicted differences.

检查第一个变化的顶部Theirstree by clicking the row called飞行员Gain. The Merge tool automatically merged this node. You can adjust the automatic choices using the buttons in theTargettree. You can review and adjust all automatic merge choices.

Resolve Conflicts

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

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

1. Select theStickCommand_radrow. This difference requires a manual merge, indicated by a pencil iconin the conflict column.

2. To resolve the line change difference in thetargetFile在仿真软件万博1manbetxEditor, change the name of the line connected to the output of the block named飞行员fromStickCommand_radto飞行员Output.

After resolving the difference, save the changes in the Simulink Editor and mark the change resolved using the manual merge iconin the conflict column.

The merge report does not update to show any changes you make in the Simulink Editor.

3. On the toolstrip, clickNextto 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. In theTargetpane, in the Mine column, select the button next toStop time.

Change Filters

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

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

Accept Changes

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.

See Also

Compare Simulink Models

Source Control in Projects

Resolve Conflicts

Compare Revisions

Customize External Source Control to Use MATLAB for Diff and Merge

Related Examples

Compare and Merge Simulink Models

Compare and Merge Simulink Models Containing Stateflow