惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
GRAHAM CLULEY
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V2EX - 技术
V2EX - 技术
The Last Watchdog
The Last Watchdog
S
Secure Thoughts
Webroot Blog
Webroot Blog
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
Hacker News: Ask HN
Hacker News: Ask HN
N
News and Events Feed by Topic
H
Heimdal Security Blog
H
Help Net Security
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
F
Full Disclosure
小众软件
小众软件
S
Securelist
罗磊的独立博客
NISL@THU
NISL@THU
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cisco Blogs
云风的 BLOG
云风的 BLOG
C
CERT Recently Published Vulnerability Notes
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
S
Schneier on Security
D
DataBreaches.Net
M
MIT News - Artificial intelligence
V
Vulnerabilities – Threatpost
N
News and Events Feed by Topic
有赞技术团队
有赞技术团队
F
Fortinet All Blogs
T
Tenable Blog
The Register - Security
The Register - Security
C
Check Point Blog
AWS News Blog
AWS News Blog
Cloudbric
Cloudbric
C
CXSECURITY Database RSS Feed - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google Online Security Blog
Google Online Security Blog
博客园 - 叶小钗
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 司徒正美

博客园 - kingBook

git 修改最后一次提交的日期 Win10 修改特定格式文件的右键快捷菜单 TypeScript async、 await、Promise LayaAir3.x 侦听程序退出 旋转力学例子 旋转力学公式 凹多边形碰撞检测 LayaAir3.x 侦听键盘事件 URP 阴影 TypeScript 里的 override TypeScript 类的自身类型 Unity 二维数组序列化 C# 匿名对象、动态属性 Cocos Creator 安卓模拟器中无法运行 Unity Editor 保存图片、缩放纹理 LayaAir3.2.0-beta.2 设置2d刚体线性速度,在不同设备(分辨率)下,表现不一致的问题 LayaAir3.x 物理2D碰撞事件 TypeScirpt 声明Map类型变量 TypeScript 声明函数类型变量
git patch
kingBook · 2026-03-24 · via 博客园 - kingBook

在日常开发中,打 patch(补丁) 是将某段代码变更应用到另一个代码库或分支的常用方式. Git 提供了两种主要方法来应用 patch,分别应用不同场景.

  1. git format-patch 生成的 Git 专用补丁文件 (.patch).
  2. git diff 生成的 UNIX 标准补丁文件 (.diff).
  • .patch 记录了内容更改,有提交记录信息,一个提交只能对应一个 patch 文件.
  • .diff 记录了内容更改,无提交记录信息,多个提交可以合并成一个 diff 文件.

一、创建 patch 和 diff 文件

  • 创建 patch 文件
:: 将最近的一个提交,生成 .patch 文件
git format-patch -1

:: 将指定提交,生成 .patch 文件
git format-patch -1 b703f4d56

:: 将(b703f4d56, 最近的一个提交] 区间的所有提交,逐个生成 .patch 文件
git format-patch b703f4d56

:: 将 (915304, 94e737] 区间的所有提交,逐个生成 .patch 文件 (提交顺序915304..94e737)
git format-patch 915304..94e737
  • 创建 diff 文件
:: 将最近的一个提交,生成 .diff 文件(文件名为 test)
git diff HEAD^ test.diff

:: 将指定提交,生成 .diff 文件
暂缺

:: 将(b703f4d56, 最近的一个提交] 区间的所有提交,生成一个 .diff 文件(文件名为 test)
git diff b703f4d56 > test.diff

:: 将 (915304, 94e737] 区间的所有提交,生成一个 .diff 文件(文件名为 test)
git diff 915304 94e737 > test.diff

二、应用 patch 和 diff 文件

  • 应用 patch 文件
:: 应用生成的 patch 文件
git apply $"C:\Users\admin\Desktop\temp\testgit\0001-add123.patch"
  • 应用 diff 文件
:: 应用生成的 diff 文件
git apply $"C:\Users\admin\Desktop\temp\testgit\test.diff"