简体   繁体   English

使用git与Dymola / Modelica进行版本控制

[英]Version control using git with Dymola/Modelica

At work I use git as a version control system and Dymola for modeling and simulation. 在工作中,我使用git作为版本控制系统,使用Dymola进行建模和模拟。

One major Issue I have is that once I touch or by mistake move a connection (more exactly the position of a part of the connecting wire) in a diagram without changing any parameters -which usually happens when discussing or explaining by showing the diagram to colleagues- git consider this as a version change or change in the file. 我遇到的一个主要问题是,一旦触摸或错误地移动连接(更准确地说是连接线的一部分的位置)而不改变任何参数 - 这通常在讨论或解释时通过向同事展示图表时发生 - git将此视为文件中的版本更改或更改。 At least the real change is in some auto-generated Modelica annotations, for example: 至少真正的变化是在一些自动生成的Modelica注释中,例如:

connect(TT_1.T, Controller.y[1]) annotation (Line(
  points={{48,-20},{48,40},{-22.5,40},{-22.5,29.25}},
  color={0,0,127},
  smooth=Smooth.None));

changed to (compare the 2nd lines) 改为(比较第2行)

 connect(TT_1.T, Controller.y[1]) annotation (Line(
  points={{48,-20},{48,38},{-22.5,38},{-22.5,29.25}},
  color={0,0,127},
  smooth=Smooth.None));

My Question therefore is: How can I prevent such an unnecessary "change" in the code on either side: git or Dymola? 因此,我的问题是:如何防止任何一方代码中出现这种不必要的“改变”:git或Dymola?

The graphical part of your model also has to be stored somewhere, and the place Modelica uses are so called annotations. 模型的图形部分也必须存储在某个地方,Modelica使用的地方就是所谓的注释。 Every model, instance of a model and also every connection has such annotations. 每个模型,模型的实例以及每个连接都有这样的注释。 The graphics do not influence the "pyhsical" behavior, but they are still important for end user convenience. 图形不会影响“pyhsical”行为,但它们对最终用户的便利性仍然很重要。
Now, if you edit some icon or connection (or, anything else) from the GUI, this change will be reflected in the code. 现在,如果您从GUI编辑某些图标或连接(或其他任何内容),此更改将反映在代码中。 And once you click the save button, the file will be written to disk and git will notice that the code has changed. 单击保存按钮后,文件将写入磁盘,git将注意到代码已更改。 Some of these changes might be on purpose (some people invest a lot of time in nice looking connections), while other changes might not be important. 其中一些变化可能是故意的(有些人会花很多时间在漂亮的连接上),而其他变化可能并不重要。 There is absolutely no way how a version control system can decide what you consider relevant, that decision is up to you. 版本控制系统绝对没有办法决定您认为相关的内容,该决定取决于您。 You can always decide NOT to save your changes (in Dymola, choose the Save None button). 您始终可以决定不保存更改(在Dymola中,选择Save None按钮)。

In addition to the changes that you are responsible for, your tool (eg Dymola) might try to be smart and do some auto-formatting. 除了您负责的更改之外,您的工具(例如Dymola)可能会尝试变聪明并进行一些自动格式化。 There are users that consider Dymolas behavior too intrusive (eg breaking lines, inserting whitespace, adding irrelevant annotations, moving comments around). 有些用户认为Dymolas行为过于干扰(例如,破坏行,插入空格,添加不相关的注释,移动注释)。 Sadly, there is not much you can do here, except of course stopping to use Dymola as an editor (and instead only use it as a simulation tool), or you can use cleanup tool like ttws (trim-trailing-white-space). 可悲的是,你在这里做的并不多,除了当然停止使用Dymola作为编辑器(而只是用它作为模拟工具),或者你可以使用像ttws这样的清理工具(trim-trailing-white-space) 。 As far as I know, Dymola does not move around your icons, so the example you showed was not introdced by Dymola. 据我所知,Dymola不会移动你的图标,所以你展示的例子并没有被Dymola所吸引。

Now, second part of your question. 现在,问题的第二部分。 If for some reason you have clicked the save button, git (and any other good version control system) allows you to revert your changes, or part of your changes, before commiting (or after commiting, but then things get more complicated). 如果由于某种原因你点击了保存按钮,git(以及任何其他好的版本控制系统)允许你在提交之前(或者在提交之后恢复你的更改或部分更改)但事情变得更复杂了。 Also, you do not have to push all your commits to the central repository. 此外,您不必将所有提交都推送到中央存储库。 The exact workflow will depend on which git client you use and whether you use a graphical user interface or the command line. 确切的工作流程取决于您使用的git客户端以及是使用图形用户界面还是命令行。 Which one do you use? 你用哪一个?
Below is a screenshot of the GitExtensions commit dialog (this image is the main reason for writing an answer instead of a comment): 下面是GitExtensions提交对话框的屏幕截图(此图像是编写答案而不是评论的主要原因):

GitExtensions提交阶段还原对话框

  • On the left top, you see all files where git has noticed a change, here you can revert whole files. 在左上方,您会看到git注意到更改的所有文件,您可以在此处还原整个文件。
  • On the left bottom, you see the staging area. 在左下角,您可以看到暂存区域。 Only the files in the staging area will be part your commit. 只有暂存区域中的文件才是您提交的一部分。
  • On the right top, you see the diff and the context menu that allows to reset single lines of code. 在右上角,您可以看到diff和上下文菜单,它允许重置单行代码。
  • On the right bottom, you would type your commit message. 在右下角,您可以键入提交消息。

There are many tutorials and books available on how to use git, you probably want to read these, as well as the manual for the git client of your choice. 有很多关于如何使用git的教程和书籍,你可能想要阅读这些,以及你选择的git客户端的手册。 Or, you simply do not click the save button when there is nothing you want to save. 或者,如果您不想保存任何内容,则根本不单击“保存”按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM