Make Changes and Merge Git Local Branch - MATLAB & Simulink (original) (raw)

You are collaborating on models that are under Gitâ„¢ source control. You work on some changes in your local branch taskBranch. When you attempt to merge your branch into the main branch, merge conflicts occur in two model files.

1. Open the example to download the supporting files.

Files and Source Control panels grouped together. Files panel on top shows 2 unmodified model files under Git source control. In the Source Control panel below, the mouse cursor points to the Branch Manager button.

2. Open the Branch Manager and switch from the main branch to the taskBranch branch.

In the Files panel, right-click and select Source Control > Branch Manager. Alternatively, use the Source Control panel to open the Branch Manager . If the Source Control icon Source Control icon is not in the sidebar, click the Open more panels button Open more panels icon and select the Source Control panel.

To switch to taskBranch, in the Branch Manager toolstrip, in the Current Branch section, select taskBranch from the available branches.

Branch Manager with the toolstrip on top, the commit graph in the middle, and detail panes on the left and right. In the toolstrip, the mouse points to the taskBranch option in the Current Branch section.

Alternatively, in the Command Window, enter these commands.

repo = gitrepo; switchBranch(repo,"taskBranch");

3. Make these changes to the sldemo_mdlref_counter and sldemo_mdlref_basic models and save the models.

Alternatively, in the Command Window, enter these commands.

topMdl = "sldemo_mdlref_basic"; refMdl = "sldemo_mdlref_counter";

load_system(refMdl); load_system(topMdl); modelNames=[refMdl,topMdl];

refBlockPath = append(refMdl,"/Switch"); set_param(refBlockPath,"Threshold","0.25"); refScopePath = append(refMdl,"/ScopeA"); set_param(refScopePath,"Name","Scope"); cstBlockPath = append(topMdl,"/C5"); set_param(cstBlockPath,"Value","110");

save_system(refMdl) save_system(topMdl)

close_system(modelNames,0)

4. Commit your changes. In the Source Control panel, click Commit. Enter a commit message and click Commit.

Alternatively, in the Command Window, enter these commands.

commit(repo,Message = "Set Fixed step size to 0.003 and set InputSignalHandling and OutputSignalHandling to Auto/Zero-order Hold.");

5. Merge the branch taskBranch into the main branch. In the Branch Manager, switch back to main branch. Then, click Merge.

Alternatively, in the Command Window, enter these commands.

mainBranch = "main"; switchBranch(repo,mainBranch); try merge(repo,"taskBranch") catch % The merge function throws an expected error because this branch merge % results in a conflict. % Unable to merge main into taskBranch.

% Caused by: % Conflicted files: % sldemo_mdlref_basic.slx % sldemo_mdlref_counter.slx end

Files and Source Control panels grouped together. Files panel on top shows 2 conflicted model files. The Branch Manager prompts that the merge resulted in conflicts.

The branch merge results in conflicts in both model files. See the next steps to resolve the conflicts.

See Also

Simulink Three-Way Merge Tool

Topics