Squash Git Commits in MATLAB - MATLAB & Simulink (original) (raw)
Main Content
This example shows how to combine multiple Git™ commits into a single commit in MATLAB®.
Open the example to download the supporting files. The example repository reflects the following scenario.
You have been working locally on a utility script saveUnsavedMFiles.m
that saves all opened files that have unsaved changes in the MATLAB Editor. You made several commits to track your incremental work. Before you share the utility script, you want to combine the incremental commits into a single commit that represents the feature.
Investigate Commit History
To see the commit history, open the Branch Manager. In the Files panel, right-click and select Source Control > Branch Manager.
Alternatively, you can open the Branch Manager from the Source Control panel
in the sidebar. If the Source Control icon is not in a sidebar, click the Open more panels button
and select the Source Control panel.
The Branch Manager shows the commit graph, branch information, and commit messages and details. In this example, you have three consecutive commits that track incremental changes to the same saveUnsavedMFiles
utility file.
You can investigate the difference between the commits in the pane on the right.
Squash Commits
To squash the commits that track the incremental changes into a single commit that represents the feature, in the commit graph, select the first and last incremental commits you want to combine. Then, right-click and select Squash Selected Commits. The Branch Manager takes all commits between the two commits you selected and combines their commit messages.
In the Squash Commits dialog box, replace the combined commit messages with a new message that describes your feature. Then, click Squash.
The commit graph now shows one combined commit instead of the three separate commits. The pane on the right shows that the difference between the selected commit and the previous commit is the addition of saveUnsavedMFiles.m
.