commit
Syntax
Description
commits all modified files to the Git™ repository commitDetails
= commit(repo
,Message=commitMessage
)repo
with the specified message
Message
and returns the commit details.
commits only the modified files specified by commitDetails
= commit(repo
,Message=commitMessage
,Files=listOfFiles
)Files
to the Git repository.
Examples
Commit All Modified Files
Open the Times Table App project and use the gitrepo
function to create a Git repository object from the currently active repository.
openExample("matlab/TimesTableProjectExample")
repo = gitrepo
repo = GitRepository with properties: WorkingFolder: "C:\myWorkSpace\examples\TimesTableProjectExample" GitFolder: "C:\myWorkSpace\examples\TimesTableProjectExample\.git" CurrentBranch: [1×1 GitBranch] (main) LastCommit: [1×1 GitCommit] (566d916) ModifiedFiles: [0×1 string] UntrackedFiles: [0×1 string] IsBare: 0 IsShallow: 0 IsDetached: 0 IsWorktree: 0
Create a new file and add it to the repository.
edit newScript.m; add(repo,"newScript.m");
Modify the timesTableGame
file in your repository.
writelines("% Add simple comment","source/timesTableGame.m",WriteMode="append");
List the modified files in the repository.
modifiedFilesList = repo.ModifiedFiles
modifiedFilesList = 2×1 string array "C:\myWorkSpace\examples\TimesTableProjectExample\newfile.m" "C:\myWorkSpace\examples\TimesTableProjectExample\source\timesTableGame.m"
Commit all modified files to the local repository.
commitDetails = commit(repo,Message="Commit all")
commitDetails = GitCommit with properties: Message: "Commit all" ID: "a774b7daed41a6efb683d9405fe80a1e0ed82b5e" AuthorName: "username" AuthorEmail: "username@mathworks.com" AuthorDate: 17-Apr-2023 12:17:03 +0000 CommitterName: "username" CommitterEmail: "username@mathworks.com" CommitterDate: 17-Apr-2023 12:17:03 +0000 ParentCommits: "566d9161131ad17ead7bc4842c2d0124c435c77e"
Commit Subset of Modified Files
Open the Times Table App project and use the gitrepo
function to create a Git repository object from the currently active repository.
openExample("matlab/TimesTableProjectExample")
repo = gitrepo
repo = GitRepository with properties: WorkingFolder: "C:\myWorkSpace\examples\TimesTableProjectExample" GitFolder: "C:\myWorkSpace\examples\TimesTableProjectExample\.git" CurrentBranch: [1×1 GitBranch] (main) LastCommit: [1×1 GitCommit] (566d916) ModifiedFiles: [0×1 string] UntrackedFiles: [0×1 string] IsBare: 0 IsShallow: 0 IsDetached: 0 IsWorktree: 0
Create a new file and add it to the repository.
edit newScript.m; add(repo,"newScript.m");
Modify the timesTableGame
file in your repository.
writelines("% Add simple comment","source/timesTableGame.m",WriteMode="append");
List the modified files in the repository.
modifiedFilesList = repo.ModifiedFiles
modifiedFilesList = 2×1 string array "C:\myWorkSpace\examples\TimesTableProjectExample\newScript.m" "C:\myWorkSpace\examples\TimesTableProjectExample\source\timesTableGame.m"
Commit only the newScript
file to the local repository.
commitDetails = commit(repo,Files="newScript.m",Message="Commit new file")
commitDetails = = GitCommit with properties: Message: "Commit new file" ID: "a774b7daed41a6efb683d9405fe80a1e0ed82b5e" AuthorName: "username" AuthorEmail: "username@mathworks.com" AuthorDate: 17-Apr-2023 12:17:03 +0000 CommitterName: "username" CommitterEmail: "username@mathworks.com" CommitterDate: 17-Apr-2023 12:17:03 +0000 ParentCommits: "566d9161131ad17ead7bc4842c2d0124c435c77e"
Input Arguments
repo
— Git repository
matlab.git.GitRepository
object
Git repository, specified as a matlab.git.GitRepository
object.
commitMessage
— Commit message
string scalar | character vector
Commit message, specified as a string scalar or a character vector.
Example: "Fix bug"
Data Types: char
| string
listOfFiles
— Files to commit
string array | character vector | cell array of character vectors
Files to commit to the local repository, specified as a string array, character vector, or cell array of character vectors. If you do not specify this input, the function commits all modified files.
Example: "newfile.m"
Data Types: char
| string
| cell
Output Arguments
commitDetails
— Details of commit
matlab.git.GitCommit
object
Details of the commit, returned as a matlab.git.GitCommit
object.
Version History
Introduced in R2023b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)