用 git format-patch 生成邮件补丁
把提交导出为可用于邮件列表的 mbox 文件。
运行 git format-patch -1 HEAD -o patches/,把最近提交写成 .patch 文件。
01命令
命令
$ git format-patch -1 HEAD -o patches/02作用说明
format-patch 把提交连同信息、作者和差异导出为邮件兼容补丁,Linux 内核等项目正是通过邮件列表评审这种补丁。它体现了 Git 工作流不止于网页 PR。
03风险
!注意: 补丁会包含作者邮箱;发送前请确认身份与收件人。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- git-format-patch documentation依据: Documents git format-patch, which prepares patches for email submission.
最后验证: 2026-10-13 · 分类: 开发者