利用dSPACE Model Compare掌握Git中的模型

発行元: 2022年03月11日

dSPACE GmbH生产软件与SIL仿真部软件开发人员Sebastian Gerhardt

Sven Siemon,技术作者,dSPACE GmbH研发治理和能力合作伙伴

在2021年Stack Overflow开发人员调查中,超过90%的受访者使用Git,并希望继续使用此分散式版本控制系统。2005年Linus Torvalds开发Git时,可能也无法预测到这一市场主导地位。许多dSPACE客户已经在使用Git或是计划即将转换,并对现代分布式版本控制系统的优势赞誉有加,例如其更快的开发速度、更大的灵活性或更多的协作。开箱即用的Git只能供用户管理文本文件,而不能管理TargetLink或Simulink ® 模型文件这样的二进制文件。可以将Model Compare集成Git中,比较和合并模型文件。

有利就有弊

Git具有许多优点,但同时也给用户带来了新的挑战,例如分支管理、文件锁定或质量管理。在处理TargetLink和Simulink ® 模型文件时,必须使用基于文件的比较方法,因为如果更改库元素,Git就会检测到库文件发生更改。因此,必须比较修改后的库文件,而不是引用库元素的模型。通过Model Compare,开发人员可以轻松简便掌控日常业务中的这些挑战。

在Git中配置和使用Model Compare

正如每个为公司提供价值的开发人员不同,每个公司的环境也都各不相同。在 《Using Model Compare with Git》小册子 中,我们提供了关于如何将Model Compare集成到您的环境的说明。今天我们重点介绍在Tortoise Git中配置和使用Model Compare作为模型文件的外部Git diff和mergetool工具。如下表所示,您必须将Model Compare指定为外部程序:

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

配置完成后,您可以继续使用Tortoise Git,就像使用文本和源文件一样。只要您想比较或合并TargetLink和Simulink模型文件中的更改,Model Compare就会打开,您可以使用其可自定义的智能比较算法和合并功能。

合并场景以及如何掌握这些场景

图1:二进制文件冲突,但没有发生模型冲突。

Git不能合并二进制文件,因此在Git中合并二进制文件(例如 *.slx文件)会自动导致二进制文件冲突。然而,Model Compare可以帮助您解决这一问题,因为它可以分析模型文件,以区分导致模型冲突的更改和不导致模型冲突的更改。如果已更改不同的模型元素,则不会发生任何模型冲突,并且可以合并这些更改(图1)。还可以使用Model Compare中的舒适复制操作来自动合并模型文件,并通过git-merge-driver将自动合并直接集成到Git中。请参阅 Using Model Compare with Git ,获取说明。

图2:二进制文件冲突和模型冲突。

如果相同的模型元素(例如,相同的Gain模块或信号线)进行了不同更改,则Model Compare会发现模型冲突(图2)。在这种情况下,Model Compare会帮助您解决冲突(图2)。我们开发Model Compare以在所有合并场景中为您提供帮助,这样您就不用担心可能发生的二进制合并冲突。

日常工作技巧

除了通过Git环境中的Model compare来比较和合并模型的配置之外,以下关于Git、Model Compare和Simulink ® 的技巧可加快您的日常工作速度:

Tool Tip Description
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.

Ob-La-Di, Ob-La-Da(生活还在继续)

我们的客户处于快速发展的时代,在dSPACE,我们始终根据客户需求努力提供最佳解决方案。Linus Torvalds用英国俚语“笨蛋”(他从披头士的歌曲《I’m So Tired》中学到这个词语)来命名Git。但我们希望本文已经为您提供了成为聪明的Git和Model Compare用户所需要的一切。如果您对在Git中使用Model Compare有任何疑问,请随时与我们联系。

Product Information 视频 Documentation

推动创新进程。我们始终在技术开发的最前沿。

欢迎订阅我们简讯,了解我们的专业技术以及产品。希望我们的成功案例能够对您有所帮助。快速了解仿真和验证的最新信息。欢迎订阅/管理dSPACE简讯和dSPACE航空速报。

Enable form call

At this point, an input form from Click Dimensions is integrated. This enables us to process your newsletter subscription. The form is currently hidden due to your privacy settings for our website.

External input form

By activating the input form, you consent to personal data being transmitted to Click Dimensions within the EU, in the USA, Canada or Australia. More on this in our privacy policy.