How to make git-show export file as UTF-8
How to make git-show export file as UTF-8
I wanted to view an old version of a file, so I ran
> git show <commit-sha>:example.less > temp.less
to export the old version as temp.less
. But the exported file ends up having UTF-16 encoding (even thought example.less
is UTF-8 encoded).
temp.less
example.less
I tried --encoding=utf-8
and --encoding=utf8
but neither worked. Besides, I would like to set this in my gitconfig if possible rather than typing it out each time.
--encoding=utf-8
--encoding=utf8
Windows 10
Git 2.15.0.windows.1
Note that Git itself stores a raw byte stream. You can access the raw byte stream at any time using
git cat-file -p <blob-hash-ID>
. It's then up to you to convert it with whatever tools you like. Using git show
may, or may not, run blobs through various byte-stream-to-encoding converters, depending on your Git version and other details. (Add Git version and OS details to your question as needed.)– torek
Sep 9 '18 at 21:14
git cat-file -p <blob-hash-ID>
git show
@torek I've edited the question
– binaryfunt
Sep 9 '18 at 21:54
1 Answer
1
First, make sure to use the latest Git for Windows (2.19-rc2), to benefit from the latest bug fixes.
Second, redirect your git show into a file (git show... >afile
), and view that file in an UTF-8-capable editor (SublimeText, Notepad++, VSCode, ...)
That will be easier than reading it in an UTF16-CMD (meaning Lucida
font + CHCP 65001
).
git show... >afile
Lucida
CHCP 65001
Note: UTF-8 is the default for git show --encoding=...
.
git show --encoding=...
I did try redirecting into a file - the problem is that file ends up with UTF-16 encoding for some reason. I know this because when I try to open the file in Brackets it says it's UTF-16 and can't open it. I've edited the question in case this wasn't clear
– binaryfunt
Sep 10 '18 at 12:23
@binaryfunt just for testing, did you try stackoverflow.com/a/10765469/6309? (
Lucida
font + Chcp 10000
or chcp 65001
), as shown in superuser.com/a/632800/141– VonC
Sep 10 '18 at 12:25
Lucida
Chcp 10000
chcp 65001
@binaryfunt ah: stackoverflow.com/a/34899308/6309 do redirect alone is not a good solution. At the very least
CHCP 65001
is needed before the redirection.– VonC
Sep 10 '18 at 12:26
CHCP 65001
Tried
> chcp 65001
then git show with and without --encoding=utf-8
, but it didn't work. Still getting a UTF-16 file. Haven't yet updated git though– binaryfunt
Sep 10 '18 at 12:45
> chcp 65001
--encoding=utf-8
@bin did you follow stackoverflow.com/a/34899308/6309?
– VonC
Sep 10 '18 at 12:52
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
The ">" prompt means you're on Windows? Then, which Windows? Which git? There are lot of various gits for Windows. For Win10, try chcp 65001.
– ddbug
Sep 9 '18 at 21:12