Main Content

Determine Order for Resolving Conflicts Using Dependency Analyzer

When collaborating on a project, a branch merge can lead to conflicted files. For a smoother merge, you can determine the optimal order in which to resolve conflicts by running a dependency analysis. Conflicts in files that are used by other files should be resolved first. Conflicts in files that do not have dependencies do not affect other files, so the conflict resolve order does not matter.


If the project dependency graph contains circular dependencies, there might not be an optimal order in which to resolve conflicts.

You can use the Dependency Analyzer to programmatically determine the optimal order in which to resolve conflicts. In the MATLAB® Command Window, run the getProjectResolveOrder function.

function fileOrder = getProjectResolveOrder()
    import matlab.sourcecontrol.Status;
    p = currentProject;
    conflictingFiles = p.Files([p.Files.SourceControlStatus] == Status.Conflicted);
    graph = p.Dependencies;
    if ~isdag(graph)
        error("Unable to recommend an optimal resolve order. The dependency graph contains circular dependencies.")
    topologicalOrder = toposort(graph);
    topologicalFiles = graph.Nodes.Name(topologicalOrder);
    fileIndices = ismember(topologicalFiles, [conflictingFiles.Path]);
    files = flip(topologicalFiles(fileIndices));
    nodependencyFiles = setdiff(cellstr([conflictingFiles.Path])',files);
    fileOrder = [files;nodependencyFiles];

ans =

  5×1 cell array

    {'C:\workSpace\examples\TimesTableApp\source\timesTableGame.m'             }
    {'C:\workSpace\examples\TimesTableApp\source\timestable.mlapp'             }
    {'C:\workSpace\examples\TimesTableApp\tests\tAnswerIsCorrect.m'            }
    {'C:\workSpace\examples\TimesTableApp\utilities\runTheseTests.m'           }

Resolve conflicts according to the listed order. For more details, see Commit Modified Project Files.

Related Topics