Resolve Conflicts in Project Using Simulink Three-Way Merge - MATLAB & Simulink (original) (raw)
This example shows how to use the Simulink® Three-Way Merge tool to resolve conflicts in Simulink models in a project. You can view and merge the Simulink model differences in the resulting report.
Simulink Model Changes and Conflicts
Download an example project with conflicts by using the Copy Command button. The example project is under Git™ source control. When you attempt to merge the changes of a colleague on the main
Git branch into your taskBranch
, the operation results in conflicts.
To resolve the conflicts using the Three-Way Merge tool, you examine your local file (Mine, in this example, the taskBranch
branch), the conflicting revision (Theirs, in this example, the main
branch), and the common ancestor of these two files (Base).
- Theirs - A colleague, working on the
main
branch, updated the pilot model subsystem to use an explicit Gain block for the amplitude of the input commands of the pilot. The colleague also updated the Simulation stop time parameter. - Mine - You changed some configuration settings for the pilot model subsystem on the t
askBranch
branch.
The Merge tool automatically merges nonconflicted differences before opening the Three-Way Merge report. Follow these steps to review the automatic merge choices, apply your desired edits, and decide how to resolve any remaining differences. After you resolve the conflicts, commit the resolved model to source control.
Open Simulink Three-Way Merge
In the Project panel, look for conflicted files. The slproject_f14
file shows a red warning icon in the source control column, which indicates a conflict.
To see a detailed report of the conflicts, right-click the slproject_f14
file and select Source Control > View Conflicts. Alternatively, in the Source Control panel, in the Modified Files section, right-click slproject_f14
file and select View Conflicts.
For easier interaction with projects under source control, group the Project and Source Control panels by dragging one panel icon next to another. If the Source Control icon is not in the sidebar, click the Open more panels button and add it.
View Changes
The Three-Way Merge tool shows the changes to the two Simulink models that cause this file conflict.
- The main, taskBranch, and Base panes show the differences between the conflicting revision, your revision, and the base ancestor of these files.
- The Target pane shows the file into which you merge changes. The tool copies this temporary file into the project when you choose to accept the merge result.
- The summary table in the bottom right corner shows that the merge tool automatically resolved four nonconflicting differences. The table also shows that you must resolve one remaining change.
You can visually examine individual differences in the model files.
- To examine a difference, click 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.
- On the Merge tab, in the Highlight section, choose the models to display by clicking the Top Model or Bottom Model buttons.
Review Automatic Merges
The Merge tool automatically merges most nonconflicted differences before opening the Three-Way Merge report.
You can review and adjust all automatic merge choices. For example, examine the first change by clicking the PilotGain
row. The Merge tool automatically merged this row by taking the change your colleague made in the main
branch. You can adjust the automatic choices using the option buttons in the Target tree. Taking your change from the
taskBranch
deletes the PilotGain
block your colleague added.
Resolve Conflicts
To resolve conflicts, follow these steps.
1. Use the Next button to navigate to the conflict. The StopTime
parameter is conflicted because you and your colleague changed it. In the Target pane, by default, the tool selects the change from your branch taskBranch
.
2. To resolve the conflict using the default selection, mark the conflict as resolved. In the Target pane, click the conflict icon in the StopTime row and click Mark as Resolved. Alternatively, right-click the StopTime row and select Mark as Resolved.
If you want to keep the change from the main
branch instead, select the option button in the
main
branch column. When you make a selection, the tool automatically marks the item as resolved and updates the row color.
3. Check the summary table to verify you resolved all conflicts.
In this example, the summary table shows that you successfully resolved all conflicts.
Tips:
- If you resolved all conflicts in the current view but the summary table title is x unresolved changes of which y are filtered, you must disable the filters to view and resolve the remaining conflicts. To clear all applied filters, click the filters next to Visible changes.
- Use the Next and Previous buttons to navigate between the unresolved changes that require your attention.
- For every item that requires resolution, the tool provides a hint to help you resolve the issue. Click the icon that appears next to the row in the Target pane.
Accept Changes
1. 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 targetFile
, and marks the conflict as resolved in the source control tool.
2. Before you commit the resolved model file to source control, perform a final review by comparing the merge changes against the current branch.
In the Project panel, right-click the model and select Source Control > View Changes.
Tips:
When you click Accept & Close, the tool prompts you if you still have conflicts to resolve. If you click Continue, the tool selects the Mine change, in this example taskBranch, to resolve all unresolved conflicts.
See Also
Tools
Topics
- Compare and Merge Simulink Models
- Compare and Merge Simulink Models Containing Stateflow
- Set Up Git Source Control
- Use Source Control with MATLAB Projects
- Review Changes in Simulink Models
- Resolve Git Conflicts
- Clone Git Repository in MATLAB
- Customize External Source Control to Use MATLAB for Diff and Merge