How do I use Git for version handling Simulink files?

49 views (last 30 days)
Hello What is the best way to version handle Simulink code using Git? I have looked at Simulink's .slx files and these seem to be binary files (as opposed to .m files that are simple text files). I am interested in being able to use Git to allow branching, merging branches and seeing the differences between two branches. Git can easily do this for text files but runs into problems with binary files. Is there a good way to handle this with Git? Best regards Nils
  1 Comment
Bogdan Bodnarescu
Bogdan Bodnarescu on 13 Jun 2022
Hello,
I am trying to use also git for the version control of a model based software project where most of my code is generated from Simulink models, but I also have some manual code in between.
From what I can see, the merge feature for the Simulink is a total failure, merge works only when the merged branch is a child of the branch where I am merging, so basically a fast forward, but if there is even the smalles difference then the merge will do a total mess of merging the models, and it will basically compare apple with pears.
What I do actually is to revert all the merged Simulink models and then manually copy the differences, but as you can imagine this is a lot of manual work and it is very easy to lose some data.
Also I have another problem, and this is the C comments generated in the header files of the generated code from the Simulink models, because I can't find any way to configure git or a diff tool so that they will see only when a difference inside these comments exists and therefore to ignore these files and not to add them as modified files to a new commit.

Sign in to comment.

Accepted Answer

Zack Peters
Zack Peters on 19 Oct 2016
Hi Nils,
The SLX file format can be considered a binary file and could be treated in GIT as any other binary file, i.e. it cannot be diff'd with a traditional text comparison tool.
As of R2016a release of MATLAB and onward there is a 3-way Diff/Merge tool supplied by the Simulink Report Generator Toolbox, which can be configured to work with your external source control tool .
HTH, ~Zack

More Answers (0)

Categories

Find more on Source Control Integration in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!