我创建了一个补丁文件,其中包含一个二进制文件:
$ git format-patch --stdout myref^ > patch.diff
但是当我尝试将其应用于:
$ git apply -p2 patch.diff
我收到错误:fatal: git diff header lacks filename information when removing 2 leading pathname components (line 2868)
。
第2868行是new file mode 100755
,这里是带有一些上下文的差异:
2866 … end of previous hunk … 2867 diff --git a/some/path/foo.png b/some/path/foo.png 2868 new file mode 100755 2869 index 0000000000000000000000000000000000000000..3c137aa6ba759f2267f75203d6d248be89043beb 2870 GIT binary patch 2871 literal 363713 2872 zcmV(@K-RyBP)xh;3K|Lk000e1NJLTq00UqE008_50ssI2p1e?20000PbVXQnQ*UN;
发生了什么事?有没有办法在没有手动修复的情况下应用这个补丁?
注意:
a/some/path/foo.png
删除2个主要路径组件会产生path/foo.png
,这是有效的。%s:\([ab]\)/some:\1:g
。这是在Mac上的git版本1.7.3.1,而补丁是在Linux上创建的。
这是一个演示此问题的补丁文件:
From 174c35d2f4a8794608eccd31b9f7d361b5ee58c3 Mon Sep 17 00:00:00 2001
From: David Wolever <david@wolever.net>
Date: Mon, 7 Jan 2013 13:31:42 -0500
Subject: [PATCH] Added binary file
---
subdir/binfile.tgz | Bin 0 -> 153 bytes
1 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 subdir/binfile.tgz
diff --git a/subdir/binfile.tgz b/subdir/binfile.tgz
new file mode 100644
index 0000000000000000000000000000000000000000..f71f21d3357260edea2fb7b4641a35031c759393
GIT binary patch
literal 153
zcmb2|=3wX(c^$yO{Pz4_zC#KUZV%7Jv4$u7$b3+>V$q5W-=o(~i~CwxWXP!KJ&(NC
zT4Pyq@_6dLr^}Qym*z%)j7Wc5++E4Nw&l{L%+*`M!aP!Y3VSD*E>64d{mt2P<}Z<B
z277AFj|yCBw_ZPA$o~DBBju}0Z{$4AtM@n_Tp#zxnu7rue3)vzamprF1`P%V0B|lt
AD*ylh
literal 0
HcmV?d00001
--
1.7.3.1
(摘自http://git.661346.n2.nabble.com/Using-git-am-p-2-with-binary-patches-td5122345.html)