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.
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
is not in the sidebar, click the Open more panels button
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.
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.
- In the
sldemo_mdlref_basic
model, in the Constant blockC5
, set the Constant value to110
. - In the
sldemo_mdlref_counter
model, change the Scope block name fromScopeA
toScope
and in the Switch blockSwitch
, set the Threshold to0.25
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
The branch merge results in conflicts in both model files. See the next steps to resolve the conflicts.
See Also
Topics
- Resolve Conflicts in Project Using Simulink Three-Way Merge
- Git in MATLAB
- SVN in MATLAB
- Use Source Control with MATLAB Projects
- Resolve Conflicts in Models Under Source Control
- Identify Order of Resolving Conflicts in Changeset
- Resolve Conflicts in Models Using Three-Way Merge
- Customize External Source Control to Use MATLAB for Diff and Merge