4

Specifically what encoding to use if the repo has both code and docs? Any .md or .htm files are saved as UTF-8, but code is cp1252 (my compiler doesn't like the 3-byte BOM which Windows adds to UTF-8 files).

As seen in Git GUI tool (Edit -> Options...):

As seen in Git GUI tool

Frankly, does it even matter what setting I choose?

My system is Windows 8.1, and the system encoding is cp1252

d-mac
  • 112
  • 1
  • 1
  • 10
  • 1
    Not using a braindead editor sounds like easily the superior fix. – tripleee Feb 21 '18 at 15:02
  • Or even switching to an actual [Braindead editor](https://github.com/hellerve/e)! (seriously, I agree with your comment, need to get my act together). – d-mac Feb 21 '18 at 15:10

1 Answers1

6

The setting in git GUI only sets the default encoding. Real encoding should be set via .gitattributes. For example:

echo '*.html encoding=utf-8' >> .gitattributes
echo '*.c encoding=cp1252' >> .gitattributes

PS. What editor do you use that you cannot configure BOM in it? I recommend to disable BOM and use one encoding for all text files.

phd
  • 82,685
  • 13
  • 120
  • 165
  • Thanks for this, I guess it's time to configure my setup properly, and then stick with UTF-8 all the way! – d-mac Feb 21 '18 at 15:12
  • 1
    filesystem-native, file and program-native character sets are all independent, counting the user interface as a separate "file". cp1047 files on a filesystem that names files with custom-composed UTF-16, processed by a utf-8 native program and merged int a cp1252 dataset for windows-95-mindset phb's has no doubt been seen in the wild. – jthill Feb 21 '18 at 15:30
  • Where are the valid encoding values listed? – daniol Mar 26 '21 at 06:43
  • @daniol `git` (just like any other) uses [`libiconv`](https://www.gnu.org/software/libiconv/) so you can try `iconv -l` in the command line. – phd Mar 26 '21 at 12:19
  • 1
    Should it be `encoding=` or `working-tree-encoding=`? – endolith Mar 17 '23 at 17:35
  • @endolith `encoding`. The user doesn't want to reencode files back and forth, just to view them properly. Not to say that the question is 5 years old and I thing Git didn't have `working-tree-encoding` 5 year ago. – phd Mar 17 '23 at 18:02