当前位置: 首页 > news >正文

使用 patch 命令打补丁

之前的这篇文章 git 导出差异 diff 文件 写了导出 diff 、patch 文件。

拿到 patch 文件,用 patch 命令可以快速的把修改内容合入,合入后在 git 上是已修改的状态,如需提交还要 add 、commit 。

patch 语法

patch --help 可以看到

Usage: patch [OPTION]... [ORIGFILE [PATCHFILE]]Input options:-p NUM  --strip=NUM  Strip NUM leading components from file names.-F LINES  --fuzz LINES  Set the fuzz factor to LINES for inexact matching.-l  --ignore-whitespace  Ignore white space changes between patch and input.-c  --context  Interpret the patch as a context difference.-e  --ed  Interpret the patch as an ed script.-n  --normal  Interpret the patch as a normal difference.-u  --unified  Interpret the patch as a unified difference.-N  --forward  Ignore patches that appear to be reversed or already applied.-R  --reverse  Assume patches were created with old and new files swapped.-i PATCHFILE  --input=PATCHFILE  Read patch from PATCHFILE instead of stdin.Output options:-o FILE  --output=FILE  Output patched files to FILE.-r FILE  --reject-file=FILE  Output rejects to FILE.-D NAME  --ifdef=NAME  Make merged if-then-else output using NAME.-m  --merge  Merge using conflict markers instead of creating reject files.-E  --remove-empty-files  Remove output files that are empty after patching.-Z  --set-utc  Set times of patched files, assuming diff uses UTC (GMT).-T  --set-time  Likewise, assuming local time.--quoting-style=WORD   output file names using quoting style WORD.Valid WORDs are: literal, shell, shell-always, c, escape.Default is taken from QUOTING_STYLE env variable, or 'shell' if unset.Backup and version control options:-b  --backup  Back up the original contents of each file.--backup-if-mismatch  Back up if the patch does not match exactly.--no-backup-if-mismatch  Back up mismatches only if otherwise requested.-V STYLE  --version-control=STYLE  Use STYLE version control.STYLE is either 'simple', 'numbered', or 'existing'.-B PREFIX  --prefix=PREFIX  Prepend PREFIX to backup file names.-Y PREFIX  --basename-prefix=PREFIX  Prepend PREFIX to backup file basenames.-z SUFFIX  --suffix=SUFFIX  Append SUFFIX to backup file names.-g NUM  --get=NUM  Get files from RCS etc. if positive; ask if negative.Miscellaneous options:-t  --batch  Ask no questions; skip bad-Prereq patches; assume reversed.-f  --force  Like -t, but ignore bad-Prereq patches, and assume unreversed.-s  --quiet  --silent  Work silently unless an error occurs.--verbose  Output extra information about the work being done.--dry-run  Do not actually change any files; just print what would happen.--posix  Conform to the POSIX standard.-d DIR  --directory=DIR  Change the working directory to DIR first.--reject-format=FORMAT  Create 'context' or 'unified' rejects.--binary  Read and write data in binary mode.--read-only=BEHAVIOR  How to handle read-only input files: 'ignore' that theyare read-only, 'warn' (default), or 'fail'.-v  --version  Output version info.--help  Output this help.Report bugs to <bug-patch@gnu.org>.

应用到打补丁上常用 patch -p1 < xxx.diff

示例

如 test_patch.diff 文件内容如下,

diff --git a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
index cb3348f7ab..a0c35bafa4 100755
--- a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -2602,6 +2602,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {@Overridepublic long interceptKeyBeforeDispatching(IBinder focusedToken, KeyEvent event,int policyFlags) {
+        Log.d(TAG, "test_patch");final boolean keyguardOn = keyguardOn();final int keyCode = event.getKeyCode();final int repeatCount = event.getRepeatCount();

把 test_patch.diff 放在和 frameworks/ 同级别的目录下,

同级别目录

使用 patch -p1 < test_patch.diff 命令,提示

aaa@compilerbbb:~/ccc/ANDROID$ patch -p1 < test_patch.diff
patching file frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java

说明打补丁完成,使用 git diff 看,是OK的。

子目录1

进入 frameworks/ 目录下,使用 patch -p1 < test_patch.diff 命令,提示

aaa@compilerbbb:~/ccc/ANDROID$/frameworks$ patch -p1 < ../test_patch.diff
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
|index cb3348f7ab..a0c35bafa4 100755
|--- a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
|+++ b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
--------------------------
File to patch:

输入 base/services/core/java/com/android/server/policy/PhoneWindowManager.java 即可解决,

aaa@compilerbbb:~/ccc/ANDROID$/frameworks$ patch -p1 < ../test_patch.diff
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
|index cb3348f7ab..a0c35bafa4 100755
|--- a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
|+++ b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
--------------------------
File to patch: base/services/core/java/com/android/server/policy/PhoneWindowManager.java
patching file base/services/core/java/com/android/server/policy/PhoneWindowManager.java

子目录2

子目录1 中,因为实际路径和 patch 文件路径有差异,需要手动输一下路径。

有没有不用输入路径的方法?有的,用 patch -p2 < ../test_patch.diff

aaa@compilerbbb:~/ccc/ANDROID$/frameworks$ patch -p2 < ../test_patch.diff
patching file base/services/core/java/com/android/server/policy/PhoneWindowManager.java
aaa@compilerbbb:~/ccc/ANDROID$/frameworks/base$ patch -p3 < ../../test_patch.diff 
patching file services/core/java/com/android/server/policy/PhoneWindowManager.java

相关文章:

使用 patch 命令打补丁

之前的这篇文章 git 导出差异 diff 文件 写了导出 diff 、patch 文件。 拿到 patch 文件&#xff0c;用 patch 命令可以快速的把修改内容合入&#xff0c;合入后在 git 上是已修改的状态&#xff0c;如需提交还要 add 、commit 。 patch 语法 patch --help 可以看到 Usage:…...

C++——类和对象[上]

目录 1.初识面向对象 2.类的引入 3.类的定义 4.成员变量的命名规则 5.类的实例化 6.类对象模型 7.this指针 1.初识面向对象 C语言是一门面向过程的语言&#xff0c;它关注的是完成任务所需要的过程&#xff1b;C是一门面向对象的语言&#xff0c;将一个任务分为多个对…...

MySQL日志

目录 一 关于mysql的设计和运行逻辑 二 MySQL的三类日志 三 对于日志的利用 插入查询 1 备份 2 删除重复数据 一 关于mysql的设计和运行逻辑 mysql在启动的时候非常占空间&#xff0c;需要申请很大的空间&#xff0c;但是有时候内存并没有那么多&#xff0c;所以OS会把my…...

TinyURL 的加密与解密、猜数字游戏、 Fizz Buzz、相对名次----2023/4/28

TinyURL 的加密与解密----2023/4/28 TinyURL 是一种 URL 简化服务&#xff0c; 比如&#xff1a;当你输入一个 URL https://leetcode.com/problems/design-tinyurl 时&#xff0c;它将返回一个简化的URL http://tinyurl.com/4e9iAk 。请你设计一个类来加密与解密 TinyURL 。 加…...

Spring boot结合SkyWalking-Trace工具类实现日志打印请求链路traceid

背景&#xff1a; 随着业务的复杂化、解耦化&#xff0c;运维人员和开发人员需要对请求链路跟踪来快速发现和定位问题&#xff0c;基于应用已经集成了SkyWalking的前提下&#xff0c;如何通过获取SkyWalking生成的统一traceId并加入打印日志中&#xff0c;方便开发人员能够根据…...

精通ES=ElasticSearch

Elasticsearch 是一个分布式、高扩展、高实时的搜索与 数据分析引擎。它能很方便的使大量数据具有搜索、分析和探索的能力。充分利用Elasticsearch的水平 伸缩性&#xff0c;能使数据在 生产环境变得更有价值。Elasticsearch 的实现原理主要分为以下几个步骤&#xff0c;首先用…...

RabbitMQ-扇形交换机(Fanout )

扇形交换机&#xff1a;Fanout Exchange扇形交换机是最基本的交换机类型&#xff0c;它所能做的事情非常简单———广播消息。扇形交换机会把能接收到的消息全部发送给绑定在自己身上的队列。因为广播不需要“思考”&#xff0c;所以扇形交换机处理消息的速度也是所有的交换机类…...

Python 学习曲线 从 Python 新手到 Pro

Python 学习曲线 从 Python新手到 Pro 使用代码片段介绍&#xff1a; Python 是世界上最通用和使用最广泛的编程语言之一&#xff0c;以其简单性、可读性和多功能性而闻名。 在本文中&#xff0c;我们将探讨一系列示例场景&#xff0c;其中代码由具有三个不同专业知识水平的程序…...

薪资18K需要什么水平?来看看98年测试工程师的面试全过程…

我的情况 大概介绍一下个人情况&#xff0c;男&#xff0c;本科&#xff0c;三年多测试工作经验&#xff0c;懂python&#xff0c;会写脚本&#xff0c;会selenium&#xff0c;会性能&#xff0c;然而到今天都没有收到一份offer&#xff01;从年后就开始准备简历&#xff0c;年…...

基于趋动云的 Stable Diffusion Webui 环境搭建

Stable Diffusion Webui 环境搭建&#xff0c;首先新建一个项目&#xff1a; 然后&#xff0c;选择镜像。注意点公开的&#xff0c;已近做好的这个镜像&#xff0c;superx创建&#xff0c;集成了miniconda3的镜像。 然后选择添加数据源&#xff0c;一样&#xff0c;还是点公开&…...

备忘录设计模式解读

目录 问题引进 游戏角色状态恢复问题 传统方案解决游戏角色恢复 传统的方式的问题分析 备忘录模式基本介绍 基本介绍 备忘录模式的原理类图 对原理类图的说明 游戏角色恢复状态实例 应用实例要求 思路分析和图解(类图) 代码实战 备忘录模式的注意事项和细节 问题引…...

股票期货模拟交易有用吗?股票期货模拟交易心得

股票期货市场为了满足新用户的需求&#xff0c;有专门的股票期货模拟交易平台&#xff0c;大家可以在这个平台上进行股票期货的模拟交易&#xff0c;这样可以通过不断总结&#xff0c;丰富我们的知识。下面整理的股票期货模拟交易实验心得&#xff0c;从股票期货模拟交易与实盘…...

2023年五月份图形化三级打卡试题

活动时间 从2023年5月1日至5月21日&#xff0c;每天一道编程题。 本次打卡的规则如下&#xff1a; 小朋友每天利用10~15分钟做一道编程题&#xff0c;遇到问题就来群内讨论&#xff0c;我来给大家答疑。 小朋友做完题目后&#xff0c;截图到朋友圈打卡并把打卡的截图发到活动群…...

【华为OD机试真题】字母组合(javapython)100%通过率 详细代码注释

字母组合 知识点回溯 时间限制:1s 空间限制:256MB 限定语言:不限 题目描述: 每个数字对应多个字母,对应关系如下: 0: a,b,c 1: d,e,f 2: g,hi 3: j,k,l 4: m,n,o 5: p,q,r 6: s,t 7:u,v 8: w,x 9: y,z 输入一串数字后,通过数字和字母的对应关系可以得到多个字母字符串 (要…...

精彩!openEuler 社区年度顶级会议发生了啥?

2023年4月20-21日&#xff0c;万涓汇流&#xff0c;奔涌向前&#xff0c;openEuler Developer Day2023(以下简称“ODD2023”)在上海以线上线下的方式圆满举办。 本次大会由开放原子开源基金会指导&#xff0c;中国软件行业协会、openEuler社区、边缘计算产业联盟共同主办&#…...

Confidential Containers发布0.5.0版本,龙蜥将基于八大特性构建开箱即用的机密容器解决方案

文/段勇帅 01 前言 机密容器&#xff08;Confidential Containers&#xff0c;简称CoCo&#xff09;是 Cloud Native Computing Foundation&#xff08;CNCF&#xff09;Sandbox 项目。目前机密容器项目的核心参与者包括阿里云、AMD、ARM、IBM、Intel、Microsoft、Red Hat、R…...

独立储能的现货电能量与调频辅助服务市场出清协调机制(Matlab代码实现)

&#x1f4a5; &#x1f4a5; &#x1f49e; &#x1f49e; 欢迎来到本博客 ❤️ ❤️ &#x1f4a5; &#x1f4a5; &#x1f3c6; 博主优势&#xff1a; &#x1f31e; &#x1f31e; &#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 …...

使用 Luckysheet 可实现 Web 的 Excel

一、写在前面 工作中会遇到excel的导入和导出&#xff0c;换个角度看&#xff0c;假如有个 web 版本的excel &#xff0c;且能上传现有的&#xff0c;修改编辑后再下载也是个不错的方案。 Luckysheet 是实现 web版Excel的一个优秀的框架。 Luckysheet &#xff0c;一款纯前端类…...

时间序列预测(一)基于Prophet的销售额预测

时间序列预测&#xff08;一&#xff09;基于Prophet的销售额预测 小O&#xff1a;小H&#xff0c;有没有什么方法能快速的预测下未来的销售额啊 小H&#xff1a;Facebook曾经开源了一款时间序列预测算法fbprophet&#xff0c;简单又快速&#xff5e; 传统的时间序列算法很多&a…...

【电科复试第一名】23上交819考研经验分享

笔者来自通信考研小马哥23上交819全程班学员 819&#xff0c;上岸经验贴&#xff0c;知无不言 初试第十一&#xff0c;复试第一&#xff0c;总分第七(与第六同分) 考研经历:本科就读与湖南某末985&#xff0c;大学时间没好好学习&#xff0c;天天打王者&#xff0c;玩steam上…...

eNSP-Cloud(实现本地电脑与eNSP内设备之间通信)

说明&#xff1a; 想象一下&#xff0c;你正在用eNSP搭建一个虚拟的网络世界&#xff0c;里面有虚拟的路由器、交换机、电脑&#xff08;PC&#xff09;等等。这些设备都在你的电脑里面“运行”&#xff0c;它们之间可以互相通信&#xff0c;就像一个封闭的小王国。 但是&#…...

K8S认证|CKS题库+答案| 11. AppArmor

目录 11. AppArmor 免费获取并激活 CKA_v1.31_模拟系统 题目 开始操作&#xff1a; 1&#xff09;、切换集群 2&#xff09;、切换节点 3&#xff09;、切换到 apparmor 的目录 4&#xff09;、执行 apparmor 策略模块 5&#xff09;、修改 pod 文件 6&#xff09;、…...

React Native 导航系统实战(React Navigation)

导航系统实战&#xff08;React Navigation&#xff09; React Navigation 是 React Native 应用中最常用的导航库之一&#xff0c;它提供了多种导航模式&#xff0c;如堆栈导航&#xff08;Stack Navigator&#xff09;、标签导航&#xff08;Tab Navigator&#xff09;和抽屉…...

SciencePlots——绘制论文中的图片

文章目录 安装一、风格二、1 资源 安装 # 安装最新版 pip install githttps://github.com/garrettj403/SciencePlots.git# 安装稳定版 pip install SciencePlots一、风格 简单好用的深度学习论文绘图专用工具包–Science Plot 二、 1 资源 论文绘图神器来了&#xff1a;一行…...

以下是对华为 HarmonyOS NETX 5属性动画(ArkTS)文档的结构化整理,通过层级标题、表格和代码块提升可读性:

一、属性动画概述NETX 作用&#xff1a;实现组件通用属性的渐变过渡效果&#xff0c;提升用户体验。支持属性&#xff1a;width、height、backgroundColor、opacity、scale、rotate、translate等。注意事项&#xff1a; 布局类属性&#xff08;如宽高&#xff09;变化时&#…...

【项目实战】通过多模态+LangGraph实现PPT生成助手

PPT自动生成系统 基于LangGraph的PPT自动生成系统&#xff0c;可以将Markdown文档自动转换为PPT演示文稿。 功能特点 Markdown解析&#xff1a;自动解析Markdown文档结构PPT模板分析&#xff1a;分析PPT模板的布局和风格智能布局决策&#xff1a;匹配内容与合适的PPT布局自动…...

Python爬虫(二):爬虫完整流程

爬虫完整流程详解&#xff08;7大核心步骤实战技巧&#xff09; 一、爬虫完整工作流程 以下是爬虫开发的完整流程&#xff0c;我将结合具体技术点和实战经验展开说明&#xff1a; 1. 目标分析与前期准备 网站技术分析&#xff1a; 使用浏览器开发者工具&#xff08;F12&…...

Java + Spring Boot + Mybatis 实现批量插入

在 Java 中使用 Spring Boot 和 MyBatis 实现批量插入可以通过以下步骤完成。这里提供两种常用方法&#xff1a;使用 MyBatis 的 <foreach> 标签和批处理模式&#xff08;ExecutorType.BATCH&#xff09;。 方法一&#xff1a;使用 XML 的 <foreach> 标签&#xff…...

Vite中定义@软链接

在webpack中可以直接通过符号表示src路径&#xff0c;但是vite中默认不可以。 如何实现&#xff1a; vite中提供了resolve.alias&#xff1a;通过别名在指向一个具体的路径 在vite.config.js中 import { join } from pathexport default defineConfig({plugins: [vue()],//…...

MySQL 主从同步异常处理

阅读原文&#xff1a;https://www.xiaozaoshu.top/articles/mysql-m-s-update-pk MySQL 做双主&#xff0c;遇到的这个错误&#xff1a; Could not execute Update_rows event on table ... Error_code: 1032是 MySQL 主从复制时的经典错误之一&#xff0c;通常表示&#xff…...