You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git apply:如何忽略标记为“Binary files ... differ”的变更?

如何避免git apply处理二进制文件时的"cannot apply binary patch..."错误

我将大量deb与rpm包存储为若干选定“种子”包的diff文件(通过git diff生成),用git apply命令应用这些diff,但只需要包中的源文件,此时会遇到类似cannot apply binary patch to bin/busybox without full index line的错误,对应的报错diff片段如下:

diff --git a/bin/busybox b/bin/busybox
deleted file mode 100755
index bfb3212..0000000
Binary files a/bin/busybox and /dev/null differ

解决方法

可以使用以下gawk脚本过滤掉所有涉及二进制文件的diff条目,该脚本运行速度足够快:

gawk '/^diff /         { printf("%s", s); s = $0 "\n"; next }
      /^Binary files / { s=""; next }
                       { s=s $0 "\n" }
      END              { print(s) }'

内容的提问来源于stack exchange,提问作者patraulea

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 12:31:11