You can customize external source control tools to use the MATLAB® Comparison Tool for diff and merge. If you want to compare MATLAB files such as live scripts, MAT, SLX, or MDL files from your source control tool, then you can configure your source control tool to open the MATLAB Comparison Tool.
MATLAB Comparison Tool provides useful merge tools for MathWorks® files and is compatible with all popular software configuration management and version control systems.
Set up your source control tool to use MATLAB as the application
for diff and merge for the file extensions you want, for example, .mlx
, .mat
, .slx
,
or .mdl
, by following these steps:
To get the required file paths and set the preference to reuse open MATLAB sessions, run this command in MATLAB:
comparisons.ExternalSCMLink.setup()
This command sets the MATLAB preference, under Comparison, called Allow external source control tools to use open MATLAB sessions for diffs and merges.
The command also displays the file paths you will copy and paste into your source control tool setup:
On Windows®:
matlabroot\bin\win64\mlDiff.exe
matlabroot\bin\win64\mlMerge.exe
On Linux®:
matlabroot/bin/glnxa64/mlDiff
matlabroot/bin/glnxa64/mlMerge
On Mac:
matlabroot/bin/maci64/mlDiff
matlabroot/bin/maci64/mlMerge
Where matlabroot
is replaced with
the full path to your installation, for example, C:\Program
Files\MATLAB\R2016b
.
Set up diff.
In the MATLAB Command Window, copy the file path
to mlDiff
, for example, C:\Program Files\MATLAB\R2016b\bin\win64\mlDiff.exe
.
In your source control tool, locate the diff setting,
and add an entry to specify what to do with a particular file extension
(for example, .slx
). Paste in the file path to mlDiff
that
you copied from the MATLAB Command Window.
After the path to the script, or in the arguments
box, add arguments to specify the input files. Look up the argument
names specific to your source control tool. Specify the inputs for
diffs, in this order: leftFile
, rightFile
.
For example, for Tortoise SVN:
"C:\Program Files\MATLAB\R2016b\bin\win64\mlDiff.exe" %base %mine
"C:\Program Files\MATLAB\R2016b\bin\win64\mlDiff.exe" %1 %2
Set up merge.
In the MATLAB Command Window, copy the file path
to mlMerge
.
In your source control tool, locate the merge setting,
and add an entry to specify what to do with a particular file extension
(for example, .slx
). Paste in the file path to mlMerge
that
you copied from the MATLAB Command Window.
After the path to the script, or in the arguments
box, add arguments to specify the input files. Look up the argument
names specific to your source control tool. Specify the inputs for
merges, in this order: base
, mine
, theirs
,
and merged
target file.
For example, for Tortoise SVN:
"C:\Program Files\MATLAB\R2016b\bin\win64\mlMerge.exe" %base %mine %theirs %merged
"C:\Program Files\MATLAB\R2016b\bin\win64\mlMerge.exe" %b %2 %1 %r
After this setup, when you use diff or merge, your external source control tool opens a report in MATLAB Comparison Tool. Use the report to view changes and resolve merges.
Your diff and merge operations use open MATLAB sessions if available, and only open MATLAB when necessary.The comparison only uses the specified MATLAB installation.