当前位置: 首页 > 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上…...

深入浅出Asp.Net Core MVC应用开发系列-AspNetCore中的日志记录

ASP.NET Core 是一个跨平台的开源框架&#xff0c;用于在 Windows、macOS 或 Linux 上生成基于云的新式 Web 应用。 ASP.NET Core 中的日志记录 .NET 通过 ILogger API 支持高性能结构化日志记录&#xff0c;以帮助监视应用程序行为和诊断问题。 可以通过配置不同的记录提供程…...

Java求职者面试指南:计算机基础与源码原理深度解析

Java求职者面试指南&#xff1a;计算机基础与源码原理深度解析 第一轮提问&#xff1a;基础概念问题 1. 请解释什么是进程和线程的区别&#xff1f; 面试官&#xff1a;进程是程序的一次执行过程&#xff0c;是系统进行资源分配和调度的基本单位&#xff1b;而线程是进程中的…...

【JVM】Java虚拟机(二)——垃圾回收

目录 一、如何判断对象可以回收 &#xff08;一&#xff09;引用计数法 &#xff08;二&#xff09;可达性分析算法 二、垃圾回收算法 &#xff08;一&#xff09;标记清除 &#xff08;二&#xff09;标记整理 &#xff08;三&#xff09;复制 &#xff08;四&#xff…...

如何应对敏捷转型中的团队阻力

应对敏捷转型中的团队阻力需要明确沟通敏捷转型目的、提升团队参与感、提供充分的培训与支持、逐步推进敏捷实践、建立清晰的奖励和反馈机制。其中&#xff0c;明确沟通敏捷转型目的尤为关键&#xff0c;团队成员只有清晰理解转型背后的原因和利益&#xff0c;才能降低对变化的…...

Django RBAC项目后端实战 - 03 DRF权限控制实现

项目背景 在上一篇文章中&#xff0c;我们完成了JWT认证系统的集成。本篇文章将实现基于Redis的RBAC权限控制系统&#xff0c;为系统提供细粒度的权限控制。 开发目标 实现基于Redis的权限缓存机制开发DRF权限控制类实现权限管理API配置权限白名单 前置配置 在开始开发权限…...

基于Uniapp的HarmonyOS 5.0体育应用开发攻略

一、技术架构设计 1.混合开发框架选型 &#xff08;1&#xff09;使用Uniapp 3.8版本支持ArkTS编译 &#xff08;2&#xff09;通过uni-harmony插件调用原生能力 &#xff08;3&#xff09;分层架构设计&#xff1a; graph TDA[UI层] -->|Vue语法| B(Uniapp框架)B --&g…...

Modbus转Ethernet IP深度解析:磨粉设备效率跃升的底层技术密码

在建材矿粉磨系统中&#xff0c;开疆智能Modbus转Ethernet IP网关KJ-EIP-101的应用案例是一个重要的技术革新。这个转换过程涉及到两种主要的通信协议&#xff1a;Modbus和Ethernet IP。Modbus是一种串行通信协议&#xff0c;广泛应用于工业控制系统中。它简单、易于部署和维护…...

python打卡day47

昨天代码中注意力热图的部分顺移至今天 知识点回顾&#xff1a; 热力图 作业&#xff1a;对比不同卷积层热图可视化的结果 import torch import torch.nn as nn import torch.optim as optim from torchvision import datasets, transforms from torch.utils.data import D…...

Xcode 16.2 版本 pod init 报错

Xcode 版本升级到 16.2 后&#xff0c;项目执行 pod init 报错&#xff1b; ### Error RuntimeError - PBXGroup attempted to initialize an object with unknown ISA PBXFileSystemSynchronizedRootGroup from attributes: {"isa">"PBXFileSystemSynchron…...

短视频时长预估算法调研

weighted LR o d d s T p 1 − p ( 1 − p ) o d d s T p ( T p o d d s ∗ p ) o d d s p o d d s T o d d s odds \frac{Tp}{1-p} \newline (1-p)odds Tp \newline (Tp odds * p) odds \newline p \frac{odds}{T odds} \newline odds1−pTp​(1−p)oddsTp(Tpodds…...