代码之家  ›  专栏  ›  技术社区  ›  n179911

如何在Git中应用修补程序文件

git
  •  9
  • n179911  · 技术社区  · 15 年前

    如何在Git中的位置存储库中应用修补程序?

    我试过 $git am<0001-add-voicemail-tab-to-contacts.patch 修补程序没有有效的电子邮件地址。

    我试过 $git应用0001-my.patch

    但我得到 致命:Git Diff头缺少文件名信息(第27行) 其中第27行是我的补丁文件中的“git binary patch”。我的补丁文件中有一个PNG。

    这是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{=
    
    1 回复  |  直到 15 年前
        1
  •  18
  •   Greg Bacon    15 年前

    我可以通过假装一个行尾问题来重现你的问题。

    $ 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)
    

    假设您运行的是Linux,请尝试

    $ dos2unix 0001-Add-Voicemail-tab-to-Contacts.patch
    $ git apply !$
    

    如果您正在运行cygwin,请执行相反的转换:

    $ unix2dos 0001-Add-Voicemail-tab-to-Contacts.patch
    $ git apply !$