merge - Merge Git branch, revision, or tag into current branch - MATLAB (original) (raw)
Merge Git branch, revision, or tag into current branch
Since R2023b
Syntax
Description
merge([repo](#mw%5F2c2c26fc-2c9b-46a1-b7d5-95bbc76cb4d4),[commitIdentifier](#mw%5Fb8241332-1bad-49af-afd8-f7aa9d1a0171))
merges the branch, commit, or tag specified by commitIdentifier
into the current branch of the Git™ repository repo
.
When you attempt to merge a branch that results in file conflicts, themerge
function reports that the merge is incomplete and lists the conflicted files. To complete the merge, resolve and commit the conflicted files.
Examples
Navigate to your repository folder and create a repository object.
Query the currently checked-out branch.
branchToMergeObj = repo.CurrentBranch
branchToMergeObj =
GitBranch with properties:
Name: "newFeature"
LastCommit: [1×1 GitCommit] (4a00f8a)
Switch to the branch into which you want to merge the newFeature
branch.
switchBranch(repo,"main");
Merge the newFeature
branch into the main
branch.
Alternatively, use the branch object to perform the merge.
merge(repo,branchToMergeObj)
Navigate to your repository folder and create a repository object.
Query the last commit on the current checked-out branch.
commitToMergeObj = repo.LastCommit
commitToMergeObj =
GitCommit with properties:
Message: "Add test for new feature"
ID: "4a00f8abca08f3f6feea94e3fb6a2f65ba48a232"
AuthorName: "username"
AuthorEmail: "username@mathworks.com"
AuthorDate: 15-Mar-2023 19:54:48 +0000
CommitterName: "username"
CommitterEmail: "username@mathworks.com"
CommitterDate: 15-Mar-2023 19:54:48 +0000
ParentCommits: [1×1 string]
Switch to the branch into which you want to merge the newFeature
branch.
switchBranch(repo,"main");
Use the commit revision specifier (ID) to merge the newFeature
branch into the main
branch.
commitID = repo.commitToMergeObj.ID; merge(repo,commitID)
Alternatively, use the commit object to merge.
merge(repo,commitToMergeObj)
Input Arguments
Revision specifiers, tag, or branch to merge into the current branch, specified as a string scalar, character vector, matlab.git.GitBranch
object, ormatlab.git.GitCommit
object.
Commit IDs support short, full, and relative commits.
Example: "08a4c49"
,"08a4c49d249a4dc3d998b473cdda186f1c05dfd0"
,"myBranch"
Data Types: char
| string
Tips
When you perform a merge, you can use the add or rm functions to mark the conflict on a file as resolved.
Version History
Introduced in R2023b