Sebastian Gerhardt, Software Developer, Production Software & SIL Simulation, dSPACE GmbH
Sven Siemon, Technical Author, R&D Governance & Competence Partners, dSPACE GmbH
In the Stack Overflow Developer Survey 2021, over 90% of all respondents use Git and want to continue using this decentralized version control system. This market dominance was probably not foreseeable when Linus Torvalds developed Git in 2005. Many dSPACE customers are already using Git or are planning to switch soon, to benefit from the advantages of modern, distributed version-control systems, e.g., faster development speeds, greater flexibility, or increased collaboration. Out-of-the box Git allows the user to manage text files but not binary files like TargetLink or Simulink® model files. Model Compare can be integrated in Git to enable you to compare and merge model files.
Git offers a variety of benefits, but at the same time it presents users with new challenges, like branch management, file locking, or quality management. When working with TargetLink and Simulink® model files, you must use a file-based comparison approach, because if you change a library element, Git detects a change in the library file. Therefore you must compare the modified library file and not the model that references the library element. With Model Compare, developers can master these challenges in their day-to-day business in a convenient and easy way.
Every company environment is different, just as every developer who provides value to your company is different. In the Using Model Compare with Git leaflet, we provide instructions on how to integrate Model Compare in your environment. However, today we focus on configuring and using Model Compare as an external Git diff- and mergetool for model files in Tortoise Git. You must specify Model Compare as an external program, refer to the following table:
|Diff Viewer||Merge Tool|
|"<Path to Model Compare Installation>\bin\ModelCompare_W.exe" %base %mine -reftitle %bname -comptitle %yname -Session Temporary||"<Path to Model Compare Installation>\ bin\ModelCompare.exe" %theirs %merged -camfile %base -reftitle %tname -comptitle %mname -camtitle %bname -Session Temporary -ComfortCopy -ConflictRes Interactive|
Once configured, you can continue to use Tortoise Git as you already do with text and source files. As soon as you want to compare or merge changes in TargetLink and Simulink model files, Model Compare opens and you can use its intelligent customizable comparison algorithms and merge functions.
Figure 1: Binary file conflict, but no model conflict.
Merging binary files in Git, e.g., *.slx files, automatically leads to binary file conflicts, because Git cannot merge binary files. However, Model Compare helps you out, as it can analyze the model files to distinguish between changes that do and changes that do not cause model conflicts. If different model elements have been changed, no model conflict occurs, and the changes can be merged (figure 1). It is then also possible to automatically merge the model files using the comfort copy operation from Model Compare and to integrate the automatic merge directly into Git via a git-merge-driver. For instructions, refer to Using Model Compare with Git.
Figure 2: Binary file conflict and model conflict.
If same model elements, e.g., the same Gain block or signal line, have been changed differently, Model Compare finds a model conflict (figure 2). In that case, Model Compare supports you in solving the conflict (figure 2). We developed Model Compare to assist you in all merge scenarios so that you do not have to be afraid of possible binary merge conflicts.
In addition to the configuration to compare and merge models via Model Compare from your Git environment, the following tips for Git, Model Compare, and Simulink® speed up your daily work:
|Git||Consider using Git Large File Storage (LFS) for binaries and large files.||For binaries or large files, e.g., *.slx (model files), *.dd (TargetLink Data Dictionary), and large *.arxml (AUTOSAR configuration) files, consider using Git LFS. If using Git LFS, Git only maintains pointers to these files stored in a remote server and only copies the current version to your local git cache to save space on the local hard drive and to speed up some Git operations.|
|Git||Check in libraries in Git.||If libraries are handled outside of Git, additional tooling is required, to ensure the correct library version for every model version is present. We recommend using Git at least for the libraries that you are planning to change. Check in the libraries in the same Git repository or use the Git submodules feature. Git is primarily a version control system and not a configuration management system.|
|Model Compare||Use running MATLAB® sessions.||In your daily work, you might have a running MATLAB® instance. Model Compare can be configured to use this instance to speed up the dump process and accelerate comparison results.|
|Model Compare||Manage your settings.||Model Compare allows you to export and import comparison settings. Use the -ComparisonSettings option to ensure equal comparison settings across the whole team.|
|Model Compare||Use temporary sessions.||If you start Model Compare from your Git environment, Git manages all files and at least one model file is temporary. The model files can be renamed or stored outside your working environment. Use the -session Temporary command to deactivate the Model Compare persistent features. This disables features and checks that are not necessary, like redundant save dialogs, to keep your focus on your work.|
|Simulink®||Save model files correctly.||If a Simulink model is saved without any changes, the saved versions differ, because some internal metadata will change on every save operation. This causes Git to detect a modification. Therefore, only save a model file if you made a change. Moreover, Simulink uses the Save All save operation by default. If you only changed a referenced element, we recommend using the Save Referenced Files operation.|
Our customers operate in fast-evolving times and at dSPACE, we always strive to deliver the best solutions for customers’ purposes. Linus Torvalds named Git after the British slang for «stupid person» he learned from the Beatles song «I’m So Tired» but we hope we have provided everything in this post that you need to be a smart Git and Model Compare user. If you have any questions on using Model Compare in Git, feel free to contact us.