如何在 git 中应用补丁文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1821267/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I apply a patch file in git
提问by n179911
How can I apply a patch in my location repository in git?
如何在 git 的位置存储库中应用补丁?
I tried $ git am < 0001-Add-Voicemail-tab-to-Contacts.patch Patch does not have a valid e-mail address.
我试过 $ git am < 0001-Add-Voicemail-tab-to-Contacts.patch 补丁没有有效的电子邮件地址。
I tried $git apply 0001-my.patch
我试过 $git apply 0001-my.patch
but I get fatal: git diff header lacks filename information (line 27) where line 27 is "GIT binary patch" in my patch file. My patch file has an png in it.
但我得到了致命的: git diff 头缺少文件名信息(第 27 行),其中第 27 行是我的补丁文件中的“GIT 二进制补丁”。我的补丁文件中有一个 png。
this is line 24 and on
这是第 24 行及以后
diff --git a/res/drawable-finger/icl.png b/res/drawable-finger/icl.png
new file mode 100644
index 0000000000000000000000000000000000000000..f78e65cf94d22059e0caeb90caee03e17166f109
GIT binary patch
literal 1697
zcmV;S244AzP)<h;3K|Lk000e1NJLTq001BW001Be1^@s6b9#F80000PbVXQnQ*UN;
zcVTj606}DLVr3vnZDD6+Qe|Oed2z{QJOBU&LrFwIRCwCNS6ygRXBd9-pOdCZnl?Wr
zT}!*JMXxLc!LeIm!`%pu!FDwmis0~S-pnf*2)mHMWH7G;(JNtBW1={AA=C-BqUf{=
回答by Greg Bacon
I was able to reproduce your problem by faking an end-of-line problem.
我能够通过伪造行尾问题来重现您的问题。
$ cp /bin/ls .
$ git add ls; git commit -m second
[master 8668716] second
1 files changed, 0 insertions(+), 0 deletions(-)
create mode 100755 ls
$ git format-patch HEAD^..HEAD
0001-second.patch
$ git reset --hard HEAD^
HEAD is now at 686ace7 first
$ unix2dos 0001-second.patch
$ git apply 0001-second.patch
fatal: git diff header lacks filename information (line 14)
Assuming you're running Linux, try
假设您正在运行 Linux,请尝试
$ dos2unix 0001-Add-Voicemail-tab-to-Contacts.patch
$ git apply !$
If you're running Cygwin, perform the opposite conversion:
如果您正在运行 Cygwin,请执行相反的转换:
$ unix2dos 0001-Add-Voicemail-tab-to-Contacts.patch
$ git apply !$