Main Content

diffCommits

List modified files between two commits

Since R2025a

    Description

    files = diffCommits(repo,firstCommit,secondCommit) returns the list of files that changed between the specified commits in the Git™ repository repo.

    example

    files = diffCommits(repo,firstCommit,secondCommit,MergeBase=tf), if tf is true, finds the merge base of firstCommit and secondCommit and returns the list of files that changed between the merge base and secondCommit.

    example

    Examples

    collapse all

    Navigate to your repository folder and create a repository object.

    repo = gitrepo;

    List all files that changed between the branches main and featureBranch.

    files = diffCommits(repo,"main","featureBranch")
    files = 
    
      3×1 table
    
                                                                      Status  
                                                                     __________
    
        "C:\myWorkSpace\example\repo\data.txt"                        Modified
        "C:\myWorkSpace\example\repo\README.md"                       Modified
        "C:\myWorkSpace\example\repo\model.slx"                       Added
    

    List only the files that have the status Modified.

    modifiedFiles = files(files.Status == "Modified",:).File
    modifiedFiles =
    
      2×1 cell array
    
        {'C:\myWorkSpace\example\repo\data.txt' }
        {'C:\myWorkSpace\example\repo\README.md'}
      

    Navigate to your repository folder and create a repository object.

    repo = gitrepo;

    Find the common ancestor of commit 40eba76 and commit d834e90 and list all files that changed between the common ancestor and d834e90.

    files = diffCommits(repo,"40eba76","d834e90",MergeBase=true)
    files = 
    
      3×1 table
    
                                                                      Status  
                                                                     __________
    
        "C:\myWorkSpace\example\repo\newData.txt"                     Added
        "C:\myWorkSpace\example\repo\README.md"                       Modified
        "C:\myWorkSpace\example\repo\mymodel.slx"                     Deleted

    Input Arguments

    collapse all

    Git repository, specified as a matlab.git.GitRepository object.

    Revision specifier (ID), specified as a string scalar, character vector, or matlab.git.GitBranch object.

    Commit IDs support short, full, and relative commits.

    Example: "08a4c49", "08a4c49d249a4dc3d998b473cdda186f1c05dfd0", "origin/Dev"

    Revision specifier (ID), specified as a string scalar, character vector, or matlab.git.GitBranch object.

    Commit IDs support short, full, and relative commits.

    Example: "08a4c49", "08a4c49d249a4dc3d998b473cdda186f1c05dfd0", "origin/Dev"

    Data Types: char | string

    Option to find the merge base of two Git commits, specified as a numeric or logical 1 (true) or 0 (false).

    Data Types: logical

    Output Arguments

    collapse all

    Modified files and their status between the specified commits in the Git repository, returned as a table.

    The status of the file can only be Added, Deleted, or Modified.

    Version History

    Introduced in R2025a