繁体   English   中英

使用 git diff --name-only 的 output 用于具有非 ASCII 字符的文件名

[英]Using output of `git diff --name-only` for file names with non-ASCII characters

git 的git diff --name-only对于不是 ASCII 的文件名不是很有用。 例子:

git init
echo Germany > Düsseldorf.txt
echo Mexico > Cancún.txt
git add *.txt

while read f
    do cat "$f"
done < <(git diff --cached --name-only)

这导致以下 output:

cat: '"Canc303272n.txt"': No such file or directory
cat: '"D303274sseldorf.txt"': No such file or directory

如何获取对进一步处理有用的暂存文件列表?

如何获取对进一步处理有用的暂存文件列表?

使用零分隔的 stream。

git diff -z --cached --name-only |
while IFS= read -r -d '' f; do
   cat "$f"
done

https://mywiki.wooledge.org/BashFAQ/020

无论如何,只需cat ,然后: git diff -z --cached --name-only | xargs -0 cat git diff -z --cached --name-only | xargs -0 cat

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM