[英]How to cope with spaces in file names when iterating results from git diff --name-only
[英]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.