0

Problem: git diff thinks the file is binary:

$ git diff e7714 foo.txt
diff --git a/foo.txt b/foo.txt
index 14e06f9..9f00c64 100644
Binary files a/foo.txt and b/foo.txt differ

I know it has to do with encoding. Running dos2unix fixes it.

$ dos2unix.exe foo.txt
dos2unix: converting UTF-16LE file foo.txt to UTF-8 Unix format...

Good, except if one forgets to run dos2unix before commit and push, the diffs between versions are not informative. Conversion to non UTF-8 encoding is due to certain tools that people use to edit files (bad tools).

SVN has pre-commit hooks to deal with code formatting and other style issues. Is something like this available for git? For example, I would like to say that files named *.txt must be UTF-8, else reject commit (or reject push, if commit-level reject is not possible).

user443854
  • 7,096
  • 13
  • 48
  • 63
  • Possible duplicate of [Can I make git recognize a UTF-16 file as text?](http://stackoverflow.com/questions/777949/can-i-make-git-recognize-a-utf-16-file-as-text) – andrybak Jun 23 '16 at 23:07
  • Firstly, this should be two separate questions: about UTF-16 and about git hooks. Secondly, both of them are most probably duplicates. – andrybak Jun 23 '16 at 23:08
  • 1
    "Pro Git" has very detailed description of git hooks: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks – andrybak Jun 23 '16 at 23:10

0 Answers0