码迷,mamicode.com
首页 > 其他好文 > 详细

Git打补丁常见问题

时间:2014-09-29 22:53:01      阅读:370      评论:0      收藏:0      [点我收藏+]

标签:git

Git打补丁常见问题

 

  往往觉得得到某个功能的补丁就认为这个功能我就已经成功拥有了,但是在最后一步的打补丁的工作也是需要相当谨慎的,甚至有可能还要比你获取这个补丁花费的时间还要多。看到好多同行遇到这个问题,且最近自己也花费近20天「获取,打,验证」一个特性功能的补丁。趁热总结一下,知识点可能不多,但是问题是相当棘手的。

 

 

$ git apply -h

usage: git apply [options] [<patch>...]

 

    --exclude <path>      don‘t apply changes matching the given path

    --include <path>      apply changes matching the given path

    -p <num>              remove <num> leading slashes from traditional diff paths

    --no-add              ignore additions made by the patch

    --stat                instead of applying the patch, output diffstat for the input

    --numstat             show number of added and deleted lines in decimal notation

    --summary             instead of applying the patch, output a summary for the input

    --check               instead of applying the patch, see if the patch is applicable

    --index               make sure the patch is applicable to the current index

    --cached              apply a patch without touching the working tree

    --apply               also apply the patch (use with --stat/--summary/--check)

    -3, --3way            attempt three-way merge if a patch does not apply

    --build-fake-ancestor <file>

                          build a temporary index based on embedded index information

    -z                    paths are separated with NUL character

    -C <n>                ensure at least <n> lines of context match

    --whitespace <action>

                          detect new or modified lines that have whitespace errors

    --ignore-space-change

                          ignore changes in whitespace when finding context

    --ignore-whitespace   ignore changes in whitespace when finding context

    -R, --reverse         apply the patch in reverse

    --unidiff-zero        don‘t expect at least one line of context

    --reject              leave the rejected hunks in corresponding *.rej files

    --allow-overlap       allow overlapping hunks

    -v, --verbose         be verbose

    --inaccurate-eof      tolerate incorrectly detected missing new-line at the end of file

    --recount             do not trust the line counts in the hunk headers

    --directory <root>    prepend <root> to all filenames

 

 

第一步检测补丁有无问题

$ git apply --check xxx.patch

能检测出现的问题有以下几种例子:

 

1. error: cannot apply binary patch to ‘xxx‘ without full index line

xxx一般会是bin/png/gif等等二进制文件 具体的原因就是patch中有指明要打上xxx文件,但是这个文件并不包含在这个patch中,仅仅是有一个名字存在其中。遇到这个问题要重视。

 

2. error: core/java/android/provider/Settings.java: patch does not apply

出现这种一般会是补丁冲突,这种一般是强制打上补丁(使用--reject)后根据产生的*.rej文件来手动解决冲突。

 

3. warning: core/java/android/view/View.java has type 100644, expected 100755

出现这种警告一般是文件内没有冲突,但是文件的权限发生变动。一般没有影响。

 

 

第二步强制打补丁

$ git apply --reject xxx.patch

执行了这一步后会产生什么样的结果,我对第一步的冲突来对应说明。

 

1.这种问题一般是制作补丁的开发人员没有将二进制文件制作到patch中云,对于这种情况不会有任何的提示,因为patch中源资源文件都没有,Git也没有什么招术来解决。最好的方法是联系补丁提供者。

 

2.这种情况是由于git apply是对比补丁中前后几行代码,如果没有出现在目标文件中,那么这就是冲突。这个是比较经常出现的,对于这种情况会生成*.rej文件,可以find ./ -name *.rej找到这些冲突的补丁,手动打上就好。

 

3.可以考虑忽略。

 

目前就这些,遇到新的问题再补充。

Git打补丁常见问题

标签:git

原文地址:http://blog.csdn.net/kangear/article/details/39675421

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!