3

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?

Marlon
  • 1,719
  • 3
  • 20
  • 42
  • Does this answer your question? [Make git diff show UTF8 encoded characters properly](https://stackoverflow.com/questions/19435071/make-git-diff-show-utf8-encoded-characters-properly) – Chris Maes May 05 '20 at 12:05
  • No. I've seen this answer in my searches before. Its difference because its about unicode character in file content, not in file name. So the suggested solution didn't work for me. – Marlon May 05 '20 at 14:05

1 Answers1

6

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>
bk2204
  • 64,793
  • 6
  • 84
  • 100