[英]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.