git format-patch
Turn commits into email-ready patch files
The 'git format-patch' command writes each commit of a range into its own numbered .patch file: the author, the date, the commit message as the email subject and body, a change summary, and the diff. Projects that review by mailing list (like Git itself and the Linux kernel) receive contributions this way, and git am turns the files back into commits.
Synopsis
git format-patch [-o <dir>] [--stdout] [-<n>] [<since> | <revision-range>]Options
Choosing the Right Option
Ways to hand over commits
Keeping author and message
| Command | Keeps authorship |
|---|---|
git diff > change.diff | No |
git format-patch + git am | Yes |
git bundle | Yes (whole commits and branches) |
Examples
Commits since main
git format-patch mainOne file per commit not on main.
The last commit
git format-patch -1Just the newest commit.
Into a folder
git format-patch main -o patchesWrite the files into patches/.
With a cover letter
git format-patch --cover-letter mainAdd a 0000 introduction email.
Workflow Examples
git format-patch main -o outgoingOne file per commit
git send-email outgoing/*.patchMail them to the list
Troubleshooting
No patch files created
Cause: The range is empty (e.g. your branch has no commits beyond main)
Check with git log --oneline main..HEAD
Tips & Pitfalls
Best Practices
- ✓Rebase on the latest main before making patches.
- ✓Keep one logical change per commit — each becomes one email.
Common Mistakes
- ✗Sending a git diff instead of format-patch — a diff loses the author, date and message.
- ✗Forgetting the range and getting nothing: format-patch needs a starting point (main, -1…).
FAQ
Yes, but git apply only changes files; git am also creates the commit with the original author and message.