Git (via TortoiseGit) modifies compiled file when a conflict is detected making it corrupted

291 views Asked by At

I'm fairly new to git so sorry for what will probably not be a 100% clear.

I am working with compiled files (more precisely .acd files from Rockwell for Studio5000 in PLC industrial automation). I'm pretty sure the format of the file is not important. We want to work on project with multiple users. We are using Git as a centralized server and the PLC's brand merge tool (example in this case is Rockwell). We have setup Rockwell's Merge tool as a MergeTool in TortoiseGit and everything is "mostly" going fine.

However, when we do a pull to refresh a local repo, conflicts are 100% to occur because the file is not a .txt file with which Git usually work. The problem is that when we pull (the conflict occurs) and we tell Git we want to merge, it modifies the local file (I'm guessing by putting THEIRS and OURS a little bit everywhere in the file) even though we don't want to resolve the conflicts this way and it corrupts the file for its default reader. The files BASE, REMOTE(THEIRS) and LOCAL(OURS) only appear when we use TortoiseGit's Edit Conflict (they do not automaticly appear when we specify we want to merge the 2 versions).

My problem is that un exeperienced and/or unattentionned person can easily push the corrupted file on the server because resolving the corrupted file (which is one click) allows the user to commit. I know that we can revert/reset to previous commits pretty easily but its kinda messy for the log history and we pretty much don't want to keep track of corrupted versions. Also it makes us lose much time since the "general user" will probably have diffulties reverting to previous version and might need help.

What I would like to do is first: When a user tries to merge files, Git doesn't modify compiled files from the working directory (working tree, etc.).

Second: I am pretty sure this is possible I just don't figure how, but I would like to automaticly generate the BASE, LOCAL and REMOTE files when selecting merge when a conflict occurs which would be more straight-forward then to have to manually select the Edit Conflict option. It occurs to me that .docx files allready do this but my .acd file doesn't. Is there an explanation?

As i said, I am fairly new and am widely opened to any ideas! :)

1

There are 1 answers

5
MrTux On BEST ANSWER

TortoiseGit does not modify a conflicted file by default, but Git does for text files.

Git does include conflict markers into text based files. If you don't want that to happen you could try to add a .gitattribtues file and declare your file as binary. binary is a shotcut for -diff -merge -text, so -merge could also be an option if the file is a text fileand you still want to see diffs.

You could also create a commit hook which checks for possible conflict markers in files before allowing to commit (cf. https://tortoisegit.org/docs/tortoisegit/tgit-dug-settings.html#tgit-dug-settings-hooks and prevent file with merge conflicts from getting committed in git).