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

标签 bash git utf-8

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/

相关文章:

git - 配置 Git over SSH 登录一次

linux - 如何在 bash 中使用全局数组?

bash - 向后台进程发送命令

Bash - 检查多个环境变量并列出所有缺失的变量

linux - 将 FQDN 和 IP 列表转换为两列 CSV

git 从特定分支历史记录创建新分支并提交

javascript - git shasum 和 Node sha1 不产生相同的哈希值

java - eclipse tomcat设置页面中的Tomcat URIEncoding ="UTF-8"

c - UTF-8 字符数在 C 中不正确

mysql - Utf8 和 latin1