Main Content

Customize External Source Control to Use MATLAB for Diff and Merge

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. For a more complete list of supported files, see visdiff. The MATLAB Comparison Tool provides tools for merging MathWorks® files and is compatible with popular software configuration management and version control systems. You can use the automerge tool with Git™ to automatically merge branches that contain changes in different subsystems in the same SLX file.

To set up your source control tool to use MATLAB as the application for diff and merge, you must first determine the full paths of the mlDiff, mlMerge, and mlAutoMerge executable files, and then follow the recommended steps for the source control tool you are using.

Finding the Full Paths for MATLAB Diff, Merge, and AutoMerge

To get the required file paths and enable external source control tools 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.

This command also displays the file paths to copy and paste into your source control tool setup. Example paths are:

  • On Windows®:

    Diff: matlabroot\bin\win64\mlDiff.exe
    Merge: matlabroot\bin\win64\mlMerge.exe
    AutoMerge: matlabroot\bin\win64\mlAutoMerge.bat
  • On Linux®:

    Diff: matlabroot/bin/glnxa64/mlDiff
    Merge: matlabroot/bin/glnxa64/mlMerge
    AutoMerge: matlabroot/bin/glnxa64/mlAutoMerge

  • On Mac:

    Diff: matlabroot/bin/maci64/mlDiff
    Merge: matlabroot/bin/maci64/mlMerge
    AutoMerge: matlabroot/bin/maci64/mlAutoMerge

where matlabroot is replaced with the full path to your installation, for example, C:\Program Files\MATLAB\R2020b.

Note

Your diff and merge operations use open MATLAB sessions when available, and only open MATLAB when necessary. The operations only use the specified MATLAB installation.

Integration with Git

 Command Line

 SourceTree

Integration with SVN

TortoiseSVN

With TortoiseSVN, you can customize your diff and merge tools based on the file extension. For example, to use MATLAB diff and merge tools for SLX files:

  1. Right-click in any file explorer window and select TortoiseSVN > Settings to open TortoiseSVN settings.

  2. In the Settings sidebar, select Diff Viewer. Click Advanced to specify the diff application based on file extensions.

  3. Click Add and fill the fields with the extension and the mlDiff executable path:

    Filename, extension or mime-type: .slx
    External Program: "C:\Program Files\MATLAB\R2020b\bin\win64\mlDiff.exe" %base %mine
  4. Click OK and repeat the same steps to add another file extension.

  5. In the Settings sidebar, select Diff ViewerMerge Tool. Click Advanced to specify the merge application based on file extensions.

  6. Click Add and fill the fields with the extension and mlMerge executable path:

    Filename, extension or mime-type: .slx
    External Program: "C:\Program Files\MATLAB\R2020b\bin\win64\mlMerge.exe" %base %mine %theirs %merged
  7. Click OK and repeat the same steps to add another file extension.

You can now use the MATLAB tools for diff and merge the same way you would use the TortoiseSVN default diff and merge applications.

Note

Automerging binary files with SVN , such as SLX files, is not supported.

Integration with Other Source Control Tools

Perforce P4V

With Perforce® P4V, you can customize your diff and merge tools based on the file extension. To use MATLAB diff and merge tools for SLX files, for example:

  1. In Perforce, click Edit > Preferences.

  2. In the Preferences sidebar, select Diff. Under Specify diff application by extension (overrides default), click Add.

  3. In the Add File Type dialog box, enter the following information:

    Extension: .slx
    Application: C:\Program Files\MATLAB\R2020b\bin\win64\mlDiff.exe
    Arguments: %1 %2
    

  4. Click Save.

  5. In the Preferences sidebar, select Merge. Under Specify merge application by extension (overrides default), click Add.

  6. In the Add File Type dialog box, enter the following information:

    Extension: .slx
    Application: C:\Program Files\MATLAB\R2020b\bin\win64\mlMerge.exe
    Arguments: %b %2 %1 %r

  7. Click Save and repeat the steps for other file extensions.

Tip

Customize the full path of the mlDiff and mlMerge executables to match both the MATLAB installation and the operating system you are using. For more information, see Finding the Full Paths for MATLAB Diff, Merge, and AutoMerge.

You can now use the MATLAB tools for diff and merge the same way you would use the Perforce default diff and merge applications.

Related Topics