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)
这导致以下输出:cat: '"Canc303272n.txt"': No such file or directory
cat: '"D303274sseldorf.txt"': No such file or directory
如何获取对进一步处理有用的暂存文件列表?
最佳答案
How can I obtain a listing of the staged files that's useful for further processing?
使用零分隔流。
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
.
关于bash - 将 `git diff --name-only` 的输出用于非 ASCII 字符的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67581692/