Main Content

Compare and Merge Apps

You can compare two apps and merge changes between one file and another using the Comparison Tool. The Comparison Tool highlights differences in the code of two apps.

Select Files to Compare

There are multiple ways to select two files and start the Comparison Tool:

  • App Designer — Go to theDesignerorEditortab and, in theFilesection, clickCompare。The Comparison Tool includes the currently open file in theFirst file or folderfield. Click theopen folderbutton to select a second item to compare, or drag and drop a file from your file browser into theSecond file or folderfield.

  • Current Folder browser — Select a file, right-click, and selectCompare Against。Click theopen folderbutton to select a second item to compare, or drag and drop a file from your file browser into theSecond file or folderfield. To select two files or subfolders to compare,Ctrl-click the file names. Then right-click and selectCompare Selected Files/Folders

  • Command Window — Use thevisdifffunction. For example, to compare the two filesExplorerE.mlappandExplorerF.mlappusing thevisdifffunction and the default text comparison, typevisdiff('ExplorerE.mlapp','ExplorerF.mlapp')。MATLAB®opens the Comparison Tool and displays the resulting comparison report.

Explore Differences

When you perform an app comparison, a new window opens and displays the two files side by side. For example, suppose that you have two filesExplorerE.mlappandExplorerF.mlappwith several differences. When you compare the two files, the Comparison Tool displays the resulting report.

Two apps being compared in the Comparison Tool . The apps have four differences between them including a difference within a line highlighted in purple, two individual lines that exist only in the right file, each highlighted in blue, and several lines that exist only in the left file, highlighted in yellow.

当比较应用,比较工具to match lines and detects code that is added, deleted, or changed. The Comparison Tool displays the total number of differences in the bottom-right corner of the comparison report and highlights the lines that do not match using the colors listed in this table.

Highlight Color Description
Purple The line contains differences.
Dark Purple The highlighted characters are different.
Blue The line exists only in right file. This can happen when the line is inserted in the right file, or when it is deleted from the left file. The corresponding line in the left file is highlighted using a gray striped pattern.
Yellow The line exists only in left file. This can happen when the line is inserted in the left file, or when it is deleted from the right file. The corresponding line in the right file is highlighted using a gray striped pattern.

To step through the results one difference at a time, use theNextandPreviousbuttons.

For information about how to configure the comparison report, seeCompare Files and Folders and Merge Files

Merge Changes

When comparing apps, you can merge changes from one app to the other. Merging changes can be useful when resolving conflicts between different versions of an app.

To begin merging, on theComparisontab, click theMerge Modebutton. Then, to replace content from the right pane with content from the left pane, click thebutton located next to the line you want to merge. You also can select a difference and, in theMergetab, click theReplace Contentbutton.

Two apps being merged in the Comparison Tool. There are four differences between the two apps. The first two differences cannot be merged and show a disabled merge button. The second two differences can be merged and show an enabled merged button.

The right pane contains the merged result. An asterisk next to the merged file name in the right pane (ExplorerF_modified.mlapp*) indicates that the file contains unsaved changes.

To undo a replacement, click thebutton between the modified lines or on theComparisontab. To revert all merges and start again, click theRefreshbutton. You also can click theRefreshbutton to update the comparison report after making changes to and saving the files in the Live Editor. Refreshing discards all merged changes.

To save your changes and return to the comparison report, click theSave Resultbutton. To return to the comparison report without saving changes, click theReturn to Comparisonbutton.

Tips for Successful Merging

你可以合并变化啊nly in editable code. Sections of code with a white background are editable. Examples of editable sections include the body of functions that you define (such as callbacks and helper functions) and the definitions of custom properties. Sections with a gray background contain non-editable generated code and therefore cannot be merged. If a change spans both an editable and non-editable section, you cannot merge it.

你可以合并变化啊nly from left to right. This makes the locations of the files in the Comparison Tool important.

If neither app contains changes in the generated code, place the file containing the changes that you want to merge in the left pane. You only can merge from left to right. To swap a file from the left pane to the right pane, click theSwap Sidesbutton before you start merging. Clicking theSwap Sidesbutton reverts any merges already made and creates a new comparison report for the original files.

If one of the apps contains changes in the generated code, place the file containing the generated code that you want in the merged result in the right pane of the Comparison Tool. To swap a file from the left pane to the right pane, click theSwap Sidesbutton before you start merging.

If both apps contain changes in the generated code, the files cannot be merged in the Comparison Tool. To merge the files, use App Designer to interactively apply the desired changes to the app

See Also

Related Topics