Automatically Merge Models
You can enable MATLAB® Git™ integration to automatically merge branches in your Git repository. MATLAB can automatically merge branches that contain changes in different subsystems, Stateflow® charts, and configuration sets in the same SLX file.
Tip
MATLAB automatically merges your model files and resolves conflicts when you are working in different subsystems.
If you are not working in different subsystems, you must merge and resolve conflicts manually. For more information, see Merge Simulink Models from the Comparison Report.
MATLAB Git integration automatically merges changes in a child subsystem of a modified subsystem. If the number of ports remains unchanged, child subsystems are independent of parent subsystems.
MATLAB does not report a conflict for nonfunctional changes such as window positions, open Editor tabs, and other graphical details.
To enable automerge for models in your Git repository:
Run this command in MATLAB.
comparisons.ExternalSCMLink.setupGitConfig();
This command automatically populates the global
.gitconfig
file. An example follows.[difftool "mlDiff"] cmd = \"C:/Program Files/MATLAB/R2022b/bin/win64/mlDiff.exe\" $LOCAL $REMOTE [mergetool "mlMerge"] cmd = \"C:/Program Files/MATLAB/R2022b/bin/win64/mlMerge.exe\" $BASE $LOCAL $REMOTE $MERGED [merge "mlAutoMerge"] driver = \"C:/Program Files/MATLAB/R2022b/bin/win64/mlAutoMerge.bat\" %O %A %B %A
Configure your Git repository to use the
mlAutoMerge
executable file. Open the.gitattributes
file in your repository and add:*.slx binary merge=mlAutoMerge *.mdl binary merge=mlAutoMerge
Now, when you merge branches that contain changes in non-overlapping parts of the same SLX file, MATLAB Git integration handles the merge automatically.
You can also enable automerge for requirement files and links. Open the
.gitattributes
file in your repository and
add:
*.slreqx binary merge=mlAutoMerge *.slmx binary merge=mlAutoMerge
For more details, see Three-Way AutoMerge Solution for Requirement Set and Link Set (Requirements Toolbox).
You can also customize external source control tools to use the MATLAB Comparison Tools and automerge functionality. For more details, see Customize External Source Control to Use MATLAB for Diff and Merge.