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.
MATLAB automatically merges your model files and resolves conflict when you are working in different subsystems.
If you are not working in different subsystems, you need to 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.
This command automatically populates the global
.gitconfigfile. For example:
[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
mlAutoMergeexecutable file. Open the
.gitattributesfile 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
*.slreqx binary merge=mlAutoMerge *.slmx binary merge=mlAutoMerge
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.