Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accent Characters in git diff output

Tags:

git

I'm trying to create a script/program to automate my build process. My main goal is to generate a .zip file based on a commit from git. I'm using git diff for that, to output the list of files changed in this commit, I'm using the following command:

git  --no-pager diff --no-renames --name-only --diff-filter=ACM <commit_id>

The problem is when the filename or folder has some portuguese especial chars, they're returned like codes. For Instance, I have a folder called :

db/alterações/2020-04-30.sql

and its returned like that in the list:

db/altera\303\247\303\265es/2020-04-30.sql

How can I make git return the special chars instead of theses codes?

like image 325
Marlon Avatar asked Sep 15 '26 04:09

Marlon


1 Answers

Git produces these filenames using the setting of core.quotePath, which defaults to true. When this option is true, bytes with the top bit set are quoted in octal. When the option is false, they are not, but other control characters still are.

Also, if you use -z, Git produces NUL-terminated strings and does not quote characters. This also has the benefit of dealing with newlines and tabs gracefully if they appear in filenames.

So, if your program can handle NUL bytes as terminators, write this:

git  --no-pager diff --no-renames --name-only --diff-filter=ACM -z <commit_id>

and if not, you can write this:

git -c core.quotepath=false --no-pager diff --no-renames --name-only --diff-filter=ACM \
    <commit_id>
like image 129
bk2204 Avatar answered Sep 16 '26 19:09

bk2204



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!