3-way Diff and Merge of Simulink Models: A Step-by-Step Guide
A three-way comparison uses the common ancestor, so SimDiff can tell an addition from a deletion before you merge.
A 3-way comparison and merge tool matters when several people change the same Simulink model in a version control system.
Why version control needs a 3-way comparison
In a team, several people often change the same model. A three-way comparison resolves conflicts by comparing two modified versions of a model against their common ancestor.
See how to compare two Simulink models, or continue here for a three-way comparison.
A 3-way diff is more exact than a 2-way diff because it tells you how the models were changed, not just how they differ. Suppose two versions were created by changing a common ancestor. A 2-way diff can only tell whether two elements are the same or different. In the table below, without the original model there is no way to know whether D was added to Model 2 or deleted from Model 1.

Now suppose the original model, the common ancestor, contained only blocks A, B, and C.

A 3-way diff examines the original model along with the two models to compare, and it can indicate how the models were changed.

You can see which changes were additions and which were deletions, not just how Model 1 and Model 2 differ.
Version control systems assume an accurate 3-way diff and merge tool is available. Simulink is a proprietary format, so a version control system’s built-in 3-way diff and merge will not support it. If you work at an automotive, aerospace, or defense company, chances are you already have SimDiff, which computes the 3-way diff and assists with the 3-way merge. If not, request a SimDiff trial.
Simple 3-way merge
How to perform a 3-way merge without version control integration
Typically you launch SimDiff from the version control client. The version control setup guides show how. You can also run a 3-way merge from SimDiff itself.
- Open SimDiff.
- Select Merge mode.
- Use the browse button or drag and drop the files into the left, right, and base model fields.
- Click the Start button.

SimDiff compares the models and shows both model hierarchies with the differences highlighted. Each difference is numbered and colored. By default, SimDiff uses blue for changes, red for deletions, and green for additions.
When you click a changed element, individual attribute differences appear in the Attributes view at the bottom.

SimDiff provides different options to make it easy to navigate through the differences.
By default, it shows subsystems at the top level collapsed. Select the top system and use the Expand-all button to expand every subsystem underneath, then scroll the model. This can be useful with small models.

Other options make large models easier to navigate. Use the navigation toolbar buttons to locate the next or previous difference, and the next or previous conflict.
You can also search for an element. The model tree filters to elements that match the search term. Use the inner navigation buttons to step through the matches.

By default, SimDiff shows the whole model, including unchanged elements. Switch to a view of only the differences by clicking the All Changes button. After a 3-way comparison, you can also filter the view to changes on the left model or the right model.

SimDiff integrates with the Simulink Editor. You can view model changes side by side in their graphical context. Double-click any element in SimDiff’s tree view and Simulink locates and highlights it.

Merging differences
SimDiff provides different options to merge differences. The easiest way to merge a single difference is to click the merge action icon in the middle column between the two model hierarchies.
To merge several changes at once, select the changes and click the Merge selected elements button in the toolbar.

You can also select any container node, such as a subsystem, and click the hierarchy merge toolbar button. Hierarchy merge automatically merges every difference underneath that does not require user input. After hierarchy merge, review conflicts and Stateflow changes. Layout can affect Stateflow simulation behavior, so those changes need extra care.

Identifying and resolving conflicts
Use the next or previous conflict toolbar buttons to move through the conflicts. A conflict shows a red merge action icon.
To keep the change from the right model, click the merge action button. Otherwise, the change from the left model remains.
