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
我该如何获取一个有用于进一步处理的暂存文件列表?
while IFS= read -r f
- anubhavagit diff
的-z
选项。该选项可以使输出使用null字符而不是换行符来分隔文件名和修改后的内容,这对于处理文件名包含空格或其他特殊字符的情况很有用。 - Biffen