Merge tools enable you to:
Resolve conflicts in model files under source control using three-way merge. Open by selecting View Conflicts.
Merge any two model files using two-way merge. Open by selecting Compare context menu items.
Merge MATLAB® Function block code using text comparison reports.
If you have a conflicted model file under source control in a project or in the Current Folder browser, right-click and select View Conflicts. You can resolve the conflicts in the Three-Way Model Merge tool. Examine your local file compared to the conflicting revision and the base ancestor file, and decide which changes to keep. You can resolve the conflict and submit your changes.
To try an example three-way merge, see Resolve Conflicts with Simulink Three-Way Merge.
In the project, locate the conflicted model file, right-click and select View Conflicts. You can only see View Conflicts in the context menu if your file is marked conflicted by the source control.
The Merge tool automatically resolves every difference that it can, and shows the results in the Target pane. Review the automerge choices, edit if desired, and decide how to resolve any remaining conflicts.
Examine the Merge report columns.
At the top, Theirs, Base, and Mine columns show the differences in the conflicting revision, your revision, and the base ancestor of both files.
Underneath, the Target shows the local file that you will merge changes into. The Merge tool already automerged the differences it can merge.
Examine a difference by clicking Next or by clicking a row in the Theirs, Base, and Mine columns.
The merge tool displays two models (or if you selected a configuration setting, you see two model Configuration Parameters dialog boxes). By default, you see Theirs and Target models.
Choose the models to display with the toolstrip buttons on the Merge tab: Top Model or Bottom Model. View the models to help you decide what to merge.
If you open the merge tool using View Conflicts, then the models Theirs, Base, and Mine are temporary files showing the conflicting revisions. Examine them to decide how to merge. The Target model is a copy of Mine containing the results of your merges in the report.
Select a version to keep for each change by clicking the buttons in the Target pane. You can merge modified, added, or deleted nodes, and you can merge individual parameters. The Merge tool selects a choice for every difference it could resolve automatically. Review the selections and change them if you want.
Look for warnings in the Conflicts column. Select a button to use Theirs, Base, or Mine for each conflicted item.
Merge blocks before lines, and merge states and junctions before merging transitions. Merge tool then attempts to connect all lines to blocks for you.
Some differences you must merge manually. In the Target pane, look for the manual merge icon in the Conflicts column that shows you must take action.
Make manual changes in the Editor. The comparison report cannot update to show any changes that you make in the Editor, so try to make manual changes after addressing all the simpler merges in the report.
After you have resolved the conflict using the Editor, in the Target pane, select the check option to mark the node as complete.
Examine the summary table to see the number of automatic merges and remaining conflicts you need to resolve.
Check for changes that are filtered out of the current view by looking at the summary table tab titles. The Filtered View and All Changes tab titles show the number of changes. By default the report hides all nonfunctional changes. Turn off active filters to view all identified changes.
When you are happy with your merge selections and any manual merges in the Target file, click Accept and Close. This action saves the target file with all your merges and marks the conflicted file resolved in the source control tool.
To save and not mark the conflict resolved, select Accept and Close > Save and Close.
To learn more about resolving conflicts in a change list of modified files in a project, see Resolve Conflicts.
If you are using source control outside of MATLAB, then you can customize external source control tools to open Three-Way Merge (or two-way merge for diffs).
For instructions, see Customize External Source Control to Use MATLAB for Diff and Merge.
If you are not using source control or you want to choose three files to merge, then you
can open Three-Way Merge using the function
the files to merge, for
slxmlcomp.slMerge(baseFile, mineFile, theirsFile, targetFile);
You can merge two Simulink® models from a comparison report. The Compare context menu items from a project or the Current Folder browser open a two-way model merge. If you are using source control and want to resolve conflicts using a three-way model merge instead, see Resolve Conflicts Using Three-Way Model Merge.
The merge feature enables you to merge two versions of a design modeled in Simulink. You can merge individual parameters, blocks, or entire subsystems. Entire subsystems can only be merged as a whole if they are fully inserted or deleted subsystems.
On the Comparison tab, click Merge Mode. The Target pane appears at the bottom of the report.
Use the same workflow as three-way merge. Use the buttons to select the differences to keep in the target file.
Merge blocks before lines, and merge states and junctions before merging transitions. See Merging Tips.
View the results in the report and the models. Click Save File. Save File copies the temporary target file over the right file in the comparison and reruns the comparison.
(Optional) To revert all merge operations, click Close Merge without saving the file.
Inspect your merge changes in the Simulink Editor. If necessary, connect any lines that the software did not connect automatically. The comparison report does not update to show any changes that you make in the Editor.
You must merge blocks before lines in the Simulink part of the report. You must merge states and junctions before merging transitions, or the report cannot make the connections.
For an example showing how to merge a change involving multiple nodes, see Compare and Merge Simulink Models Containing Stateflow.
Not all parameters can be merged. In this case, only one radio button is shown in the target pane indicating the version that is in the target model.
For information on merging between models with identical names, see Comparing Models with Identical Names.
To merge differences in MATLAB Function block code, create a comparison report for the parent models.
Click the Merge Mode button.
This creates and opens a third file called targetFile. It can contain the changes from either the left or right model.
Use the buttons in the right of the report to select changes you want in the target file.
Save these changes over the right model using the Save File toolstrip button.