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

时间:2016-04-22 06:22:09

标签: git modelica dymola

在工作中,我使用git作为版本控制系统,使用Dymola进行建模和模拟。

我遇到的一个主要问题是,一旦触摸或错误地移动连接(更确切地说是连接线的一部分的位置)而不改变任何参数 - 通常在讨论或解释时通过显示图表给同事 - git认为这是文件中的版本更改或更改。至少真正的变化是在一些自动生成的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));

更改为(比较第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));

我的问题是: 我怎样才能防止任何一方代码中出现这种不必要的“改变”:git或Dymola?

1 个答案:

答案 0 :(得分:3)

The graphical part of your model also has to be stored somewhere, and the place Modelica uses are so called annotations. 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.
Now, if you edit some icon or connection (or, anything else) from the GUI, this change will be reflected in the code. And once you click the save button, the file will be written to disk and git will notice that the code has changed. 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).

In addition to the changes that you are responsible for, your tool (e.g. Dymola) might try to be smart and do some auto-formatting. There are users that consider Dymolas behavior too intrusive (e.g. breaking lines, inserting whitespace, adding irrelevant annotations, moving comments around). 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). As far as I know, Dymola does not move around your icons, so the example you showed was not introdced by 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). 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. 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 Commit Stage Revert dialog

  • On the left top, you see all files where git has noticed a change, here you can revert whole files.
  • 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.
  • 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. Or, you simply do not click the save button when there is nothing you want to save.