0

For our projects we are using software TwinCAT which is based on Visual Studio (this means it is managed using VS project files) and we got this problem:

By just opening project there are created changes in project files. These changes are unimportant identifiers or sums of Target device configurations and all these can be discarded. When undoing changes in TwinCAT, these changes are often redone by TwinCAT straight after undiong them with git so it is impossible to switch branches or pull commits without unloading project or using external tools.

Question is whether there is way to include undo command while checking out or pulling or whether these can be forced. I know this is terrible way of managing git and that there is possibility of loosing work.

  • You can create an alias that stashes affected files, does the operation and then unstashes them. Won't handle conflicts though. – fredrik Aug 02 '21 at 13:08
  • Rather than try to undo as asked, to handle this situation I typically add those "unimportant files" to a `.gitignore` file and remove them from the repo. This way your editor can do what it needs to do and those changes won't even be tracked by git. – underrun Aug 02 '21 at 13:23
  • @underrun problem with this is that these files contain some unimportant data but also some very important data since these files are actually Visual Studio project files – Tomáš Rompotl Aug 02 '21 at 13:30
  • Then contact the supplier of the tool and ask them to move the "crap" data out to a separate file. – fredrik Aug 02 '21 at 13:34
  • Could you post a sample project file before and after the "unimportant" changes? – David Deutsch Aug 02 '21 at 15:30
  • Visual Studio project files often don't need to be part of the repository at all. You can version a CMakeLists.txt and generate project files as the need arises. Any local kind of data should either not be there or can be provided as a config or set of variables etc. – Koenigsberg Aug 02 '21 at 15:43
  • like @Koenigsberg mentioned you can keep the necessary files that won't conflict between uses or contain necessary changes. just because they aren't in your git repo doesn't mean they won't be in your directory - the files will stay there but they'll be unique to each person editing. – underrun Aug 03 '21 at 22:16

3 Answers3

2

You cannot really avoid that in twincat. But if you use git you can minimize changes.
What you describe are most of the time not really changes but the blocks of ids just move inside the file.

In Beckhoff TwinCAT Visual Studio settings I would recommend 2 settings if you use git:

  • Set a project setting "Minimize Id changes in TwinCAT files". Described here: Project Setting Ids - You only have to do this once for each project and everyone on the team will have this change.

enter image description here

  • Set "Separate LineIDs". This is not for project changes but changes in source files. You get less changes in source files just because you are debugging and setting breakpoints. As this already changes LineIDs. It generates a separate file for them instead of including them in the source file. This LineIds.dbg file can be ignored in .gitignore. See: LineIDs - But this setting is a Visual Studio setting. Every developer on the team needs to make that setting or the changes will come back in the files by the developers that don't have the setting.

So to sum it up it does not prevent the changes you are talking about but minimizes them substantially.
When it still happens I checkin the changes with my next change and it "silences" the ID changes for a while.

Maybe this will be addressed by Beckhoff in a future release.

Uwe Hafner
  • 4,889
  • 2
  • 27
  • 44
1

I think what you're looking for are git filters! They allow you to ignore specific changes in certain files. In that article I also mention other tips which you can use to minimize changes in your files.

Roald
  • 2,459
  • 16
  • 43
  • very interesting. Didn't know about filters. Yet I am not sure if it could solve the problem. Can you filter out complete lines that were moved up or down in a file? They can be numerous. It usually isn't just one line. – Uwe Hafner Aug 06 '21 at 20:36
  • Well mostly depends on your `sed`/`awk`/`perl` bash skills. Single lines shouldn't be too much of an issue for `sed`. For multiline matches `perl` is a better option. Just give it a go to see if it works in your case. – Roald Aug 06 '21 at 20:44
0

git checkout -m branch-name will switch branches and merge uncommitted changes to target branch. https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt--m

git checkout -f branch-name will force git to switch branches, even if there are uncommited changes. Changes will be lost. https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt--f

I'm usually unloading TwinCAT project before switching branches, as VS will prompt me to reload anyway

Jacek Domański
  • 563
  • 3
  • 7