gpt4 book ai didi

bash - 将 `git diff --name-only` 的输出用于非 ASCII 字符的文件名

转载 作者:行者123 更新时间:2023-12-03 21:41:15 25 4
gpt4 key购买 nike

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
如何获取对进一步处理有用的暂存文件列表?

最佳答案

How can I obtain a listing of the staged files that's useful for further processing?


使用零分隔流。
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 .

关于bash - 将 `git diff --name-only` 的输出用于非 ASCII 字符的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67581692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com