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
相关产品推荐
相关产品推荐

