reddit / emacs

Org-mode files as binaries for git: "Binary files a/foo.org and b/foo.org differ"

publicvoit · 2022-04-25 08:39
Hi, I do have an issue with git recognizing four of my Org-mode files as binary. This has an impact on [my workflow to detect unwanted changes](https://karl-voit.at/2014/08/20/org-losses-determining-post-commit/) which caused an issue in the recent days I did not recognize. In order to revert the unwanted changes, I do have to find my workflow for that. But first, I want to make sure that those Org-mode files are (again) treated as non-binary by git. Has anybody an idea on the things going on here that led to binary detection? How can I locate the characters that might lead to that wrong conclusion? Thanks!
whudwl · 2022-04-25 10:06
I guess if you have a file that you can use to reproduce the issue, you can cut the file in half and check each half into a new git repo and see what happens? if one of the halves has problem, then cut it in half and repeat? kind of like bisect.
publicvoit · 2022-04-25 11:09
Yes, I know bisect from git where you jump around in the commit history. If there are no direct methods, I probably have to invest the time to do that although it is a tedious task. I did a quick search on GitHub and with my search engine: there isn't a general purpose bisect tool I could find so far. This would be very handy.
publicvoit · 2022-04-25 11:32
**Success**: I found out that the UNIX/Linux tool `file` also returned "data" for exactly the files that had issues in git. So there is a chance that git and file are using the same algorithm to determine content type. With that knowledge, **bisecting was easy**: copying the file to a temp directory, removing half of its content, check `file foo.org` if it is still "data". If not, the issue is located in the part that was removed in the previous iteration. If yes, the issue remains in the rest. In my case, the issue was caused by different things. Mostly, it has been output blocks of babel scripts that contained DOS line ending characters or other characters that are problematic.
frustrated-nerd · 2022-04-25 14:06
The general technique is called delta debugging, and can be implemented in around 20-50 lines of code.
ieure · 2022-04-25 15:41
This is a Git problem, not an Org/Emacs one. Correct solution is to edit `.git/info/attributes` in your Org repo and add *.org diff To it. Git uses a heuristic to determine if a file is binary or text, and as you've found, heuristics aren't 100% reliable. That configuration option will tell Git to always treat them as diffable text.
publicvoit · 2022-04-25 16:49
This is great. Now I can overrule this anomaly - thank you very much!