Making maintainer-friendly "git am" single and multi-patches

Last updated on
17 September 2020

Creating git-am patches

Creating a single-commit patch

Git can output patches that include committer information. To generate them, commit your work in one commit and then use git format-patch
git format-patch -1
which will autogenerate a filename like "0001-foo.patch" (which you then can rename) and save it in the current dir. To save into e.g. parent dir use
git format-patch -1 -o ..
and to save to a named file use this
git format-patch -1 --stdout >[project_name]-[short-description]-[issue-number]-[comment-number].patch

Creating multiple commit patches

(Just for education, you won't need this for d.o workflow)
You can do
git format-patch -17
to save the last 17 commits to 17 files named like "0001-foo.patch", "0002-foo.patch". Use the "-o" to change output dir.

Creating a multipatch

Creating a single patch containing multiple commits is really helpful for d.o workflow (until we get somthing better ;-). It has 2 main use cases:

  • You can distiguish your commit ("interdiff") from the previous commits, preserving all committer info
  • You can split monster changes into simple, reviewable commits

Put 17 commits into a file
git format-patch -17 --stdout >../[project_name]-[short-description]-[issue-number]-[comment-number].patch
Or all commits in your feature branch that branched from 8.x-1.x
git format-patch 8.x-1.x --stdout >../[project_name]-[short-description]-[issue-number]-[comment-number].patch

Applying git-am patches

Use git am like this:
git am patchfile.patch
and if they want
git am --signoff patchfile.patch

If it's a multipatch, they can interactively-rebase, squash, no-ff-merge and do whatever git voodoo they like then.

Tags

Help improve this page

Page status: No known problems

You can: