Customize External Source Control to Use MATLAB for Diff and Merge - MATLAB & Simulink (original) (raw)

You can customize external source control tools to use the MATLAB® Comparison Tool for diff and merge. To compare MATLAB files such as MLX, MAT, SLX, or MDL files from your source control tool, 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, SLMX, SLREQX, and SLTX files. For more information, see Automatically Merge Models Locally and in CI Pipeline.

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, andmlAutoMerge executable files, and then follow the recommended steps for the source control tool you are using.

Finding Full Paths for MATLAB Diff, Merge, and AutoMerge

To get the required file paths of the mlDiff,mlMerge, and mlAutoMerge executable files, run this command in MATLAB:

comparisons.ExternalSCMLink.setup()

This command prints the file paths to copy and paste into your source control tool setup. Example paths on Windows® are:

Diff: C:\Program Files\MATLAB\R2025a\bin\win64\mlDiff.bat

Merge: C:\Program Files\MATLAB\R2025a\bin\win64\mlMerge.bat

AutoMerge: C:\Program Files\MATLAB\R2025a\bin\win64\mlAutoMerge.bat

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

To configure MATLAB diff and merge tools with command-line Git:

  1. Run this command in MATLAB.
    comparisons.ExternalSCMLink.setupGitConfig()
    This command displays the full paths of the mlDiff,mlMerge, and mlAutoMerge executable files. It also automatically populates the global.gitconfig file. For example:
    [difftool "mlDiff"]
    cmd = "C:/Program Files/MATLAB/R20xxb/bin/win64/mlDiff.bat" LOCALLOCAL LOCALREMOTE
    [mergetool "mlMerge"]
    cmd = "C:/Program Files/MATLAB/R20xxb/bin/win64/mlMerge.bat" BASEBASE BASELOCAL REMOTEREMOTE REMOTEMERGED
    [merge "mlAutoMerge"]
    driver = "C:/Program Files/MATLAB/R20xb/bin/win64/mlAutoMerge.bat" %O %A %B %A
    Note
    You need to do step 1 only once for your Git setup.
  2. Configure your repository to use the mlAutoMerge executable file. Open the .gitattributes file in your repository and add:
    *.slx binary merge=mlAutoMerge
    Now, when you merge branches that contain changes in different subsystems in the same SLX file, MATLAB handles the merge automatically.

To run the MATLAB diff and merge tools from command-line Git, use git difftool and git mergetool:

SourceTree

SourceTree is an interactive GUI tool that visualizes and manages Git repositories for Windows and Mac.

  1. Configure the MATLAB diff and merge tools as SourceTree external tools:
    1. With SourceTree open, click > .
    2. On the Diff tab, under External Diff / Merge, fill the fields with the following information:
      External Diff tool: Custom
      Diff Command: C:\Program Files\MATLAB\R20xxb\bin\win64\mlDiff.bat
      Arguments: LOCALLOCAL LOCALREMOTE
      Merge tool: Custom
      Merge Command: C:\Program Files\MATLAB\R20xxb\bin\win64\mlMerge.bat
      Arguments: BASEBASE BASELOCAL REMOTEREMOTE REMOTEMERGED
  2. Configure your repository to automerge changes in different subsystems in the same SLX file using the mlAutoMerge executable file:
    1. Open the global .gitconfig file and add:
      [merge "mlAutoMerge"]
      driver = "C:/Program Files/MATLAB/R20xxb/bin/win64/mlAutoMerge.bat" %O %A %B %A
    2. Open the .gitattributes file in your repository and add:
      *.slx binary merge=mlAutoMerge

To use the MATLAB diff tool from within SourceTree, right-click a modified file underUnstaged files and select External Diff.

To use the MATLAB merge tool when SourceTree detects a merge conflict, select theUncommitted changes branch, right-click a modified file, and select > .

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 > to open TortoiseSVN settings.
  2. In the Settings sidebar, select . 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\R20xxb\bin\win64\mlDiff.bat" %base %mine
  4. Click OK and repeat the same steps to add another file extension.
  5. In the Settings sidebar, select . ClickAdvanced 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\R20xxb\bin\win64\mlMerge.bat" %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

SVN does not support automerging binary files, such as SLX files.

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 > .
  2. In the Preferences sidebar, selectDiff. Under Specify diff application by extension (overrides default), clickAdd.
  3. In the Add File Type dialog box, enter the following information:
    Extension: .slx
    Application: C:\Program Files\MATLAB\R20xxb\bin\win64\mlDiff.bat
    Arguments: %1 %2
  4. Click Save.
  5. In the Preferences sidebar, selectMerge. Under Specify merge application by extension (overrides default), clickAdd.
  6. In the Add File Type dialog box, enter the following information:
    Extension: .slx
    Application: C:\Program Files\MATLAB\R20xxb\bin\win64\mlMerge.bat
    Arguments: %b %2 %1 %r
  7. Click Save and repeat the steps for other file extensions.

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

See Also

Topics