簡體   English   中英

使用 git diff --name-only 的 output 用於具有非 ASCII 字符的文件名

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM