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 am -3 -k后假设有冲突,不要运行git checkout。假设不愿意改动冲突文件,佯装改动一下,加入进去才干进行下一步。

git --git-dir=../other_proj_dir/.git format-patch -k -1 --stdout xxxxxxxxxxxxxxxxxx | git am -3 -k

git am相同有--reject选项,加入这个选项能够将能打上的补丁先打上,冲突的文件生成*.rej文件。

Git打补丁常见问题的更多相关文章

  1. Git 打补丁流程

    A. 使用git制作补丁时, 需要创建一个新的分支, 修改之后再提交只需要修改需要修改的文件, 并使用git -format-patch -M master 将当前的分支与主分支(master)进行比 ...

  2. Git 使用心得 & 常见问题整理

    开源Linux 回复"读书",挑选书籍资料~ Git 流程图 Workspace:工作区 Index / Stage:暂存区 Repository:仓库区(或本地仓库) Remot ...

  3. git 的补丁使用方法

    1.生成补丁 format-patch可以基于分支进行打包,也可以基于上几次更新内容打包. 基于上几次内容打包 git format-patch HEAD^  有几个^就会打几个patch,从最近一次 ...

  4. GIT使用—补丁与钩子

    一.补丁 生成补丁 [root@localhost buding]# echo B > file;git add file;git commit -m "B" [master ...

  5. Git 应用补丁报错 “sha1 information is lacking or useless”

    因为现场代码在客户局域网内,不能连接到公司网络,所以一般更新的时候都是打补丁, 然后在客户现场应用补丁,但是最近在应用补丁的时候出现了如下问题: ... fatal: sha1 information ...

  6. git打补丁、还原补丁

    打补丁.还原补丁 1.两个commit间的修改(包含两个commit,<r1>.<r2>表示两个提交的版本号,<r1>是最近提交) git format-patch ...

  7. GIT打补丁 - patch和diff应用

    一. 准备工作: [root@guangzhou gittest]# git br * master [root@guangzhou gittest]# git chk -b patch-test1 ...

  8. git操作之常见问题解决方案

    一.版本不一致 1. 错误信息: > git push -u origin master To ******.git ! [rejected] master -> master (non- ...

  9. git 安装及常见问题处理

    卸载掉自带的: yum remove git 安装: yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-de ...

随机推荐

  1. activity_main.xml: java.lang.NullPointerException

    1.错误描写叙述 eclipse.buildId=4.4.0.I20140606-1215 java.version=1.7.0_67 java.vendor=Oracle Corporation B ...

  2. Javascript新手集中营

        javascript是世界上最流行的编程语言,也许没有之一,看看github,stackoverflow上面的开源项目和问答就可略知一二.它可以用来开发web app.服务器.或者联合nati ...

  3. C语言笔记之结构体

    结构的本质是C语言的一种数据抽象,通俗的说,是基本数据类型的重组. 为什么要重组呢?由于基本数据类型不够用了.为什么不够用了呢?由于须要的信息类型太多了. 这是一个非常大的话题.信息本来是没有什么类型 ...

  4. 给一个非常长的字符串str 另一个字符集比方{a,b,c} 找出str 里包括{a,b,c}的最短子串。要求O(n)

    给一个非常长的字符串str 另一个字符集比方{a,b,c} 找出str 里包括{a,b,c}的最短子串.要求O(n). 比方,字符集是a,b,c,字符串是abdcaabcx,则最短子串为abc. 设置 ...

  5. OpenCV-Python教程(5、初级滤波内容)

    本篇文章介绍如何用OpenCV-Python来实现初级滤波功能. 提示: 转载请详细注明原作者及出处,谢谢! 本文介绍使用OpenCV-Python实现基本的滤波处理 本文不介绍滤波处理的详细概念,所 ...

  6. 深入理解Tomcat系列之一:系统架构(转)

    前言 Tomcat是Apache基金组织下的开源项目,性质是一个Web服务器.下面这种情况很普遍:在eclipse床架一个web项目并部署到Tomcat中,启动tomcat,在浏览器中输入一个类似ht ...

  7. Windown安装Mysql安装图解

    一.MYSQL的安装 1.打开下载的mysql安装文件mysql-5.0.27-win32.zip,双击解压缩,运行“setup.exe”. 2.选择安装类型,有“Typical(默认)”.“Comp ...

  8. Android 监听SMS短信

    当设备接收到一条新的SMS消息时,就会广播一个包括了android.provider.Telephony.SMS_RECEIVED动作的Intent. 注意,这个动作是一个字符串值,SDK 1.0不再 ...

  9. 利用泛型抽取Dao层,加事务注解问题(java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType)

    想利用泛型抽取BaseDao层,简化操作时出现故障: @Transactional这个注解是能够继承的.于是就想写在抽取的BaseDao层上,让实现的类能够不用写@Transactional,就可开启 ...

  10. Js中的onblur和onfocus事件

    html页面中,诸如按钮.文本框等可视元素都具有拥有和失去焦点的事件,这些事件在响应鼠标或键盘动作时都可激发预设的操作.本文以文本框获得和失去焦点为例简单讲解onfocus和onblur的应用. 一. ...