[git] How to generate a git patch for a specific commit?

Try:

git format-patch -1 <sha>

or

git format-patch -1 HEAD

According to the documentation link above, the -1 flag tells git how many commits should be included in the patch;

-<n>

     Prepare patches from the topmost commits.


Apply the patch with the command:

git am < file.patch