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
如何获得对进一步处理有用的暂存文件列表?
如何获得对进一步处理有用的暂存文件列表?
使用零分隔流。
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
。