Main Content

saveFileRevision

Save revision of file to disk

Since R2025a

    Description

    saveFileRevision(repo,filename,fileDestination,commitID) saves the revision commitID of filename to fileDestination on disk in the Git™ repository repo.

    example

    Examples

    collapse all

    Navigate to your repository folder and create a repository object.

    repo = gitrepo;

    Save the revision 40eba76 of the data.txt file to disk.

    file = fullfile(repo.WorkingFolder,"data.txt");
    ancestor = fullfile(repo.WorkingFolder,"data_ancestor.txt");
    saveFileRevision(repo,file,ancestor,"40eba76");
    

    Compare the data.txt file to revision 40eba76.

    visdiff(file,ancestor)

    Input Arguments

    collapse all

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

    Name or path of the file to save, specified as a string scalar or a character vector.

    Specify a full path or a path relative to the current folder.

    Example: "myfile.slx", "../myfile.txt"

    Data Types: char | string

    File destination, specified as a string scalar or a character vector.

    Specify a full path or a path relative to the current folder.

    Example: "file_id08a4c49.slx", "../myfile_ancestor.txt"

    Data Types: char | string

    Revision specifier (ID), specified as a string scalar, character vector, or matlab.git.GitBranch object. If you do not specify this input, the function saves the HEAD revision of the file.

    Commit IDs support short, full, and relative commits.

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

    Data Types: char | string

    Version History

    Introduced in R2025a