Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine file encoding?

Tags:

git

encoding

Is there a git command that returns file encoding like file in Linux? That completely describes my problem. I tried searching Google but found nothing.

like image 915
nmax Avatar asked Jun 14 '26 16:06

nmax


1 Answers

Git itself has no idea of the encoding of a file (stored as a blob, meaning as an arbitrary binary data).
See "What is the format of a git “blob”?".

The command file can still be used after a git checkout.
Or piped after a git show to read the content of a specific file, e.g.:

$ git show @~2:README.md | file -
/dev/stdin: ASCII text

tells that the file ./README.md 2 commits ago had an ASCII encoding - notice the last dash (-) denoting STDIN.

While this command:

$ git show :README.md | file -
/dev/stdin: Unicode text, UTF-8 (with BOM) text, with CRLF line terminators

tells that the same file staged in git's 'index' is gonna be Windows encoded.

like image 68
VonC Avatar answered Jun 16 '26 07:06

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!