Last Updated: February 25, 2016
·
1.918K
· wallin

Generate and apply a patch for commits in Git

Use this to generate a patch file for any number of git commits, in this example the last 4:

git format-patch -4 HEAD --stdout > 0001-last-4-commits.patch

To test if the patch applies cleanly:

git apply --check 0001-last-4-commits.patch

To finally apply the patch:

git am --signoff 0001-last-4-commits.patch