How do I simply create a patch from my latest git commit?

claj picture claj · Feb 22, 2012 · Viewed 188.3k times · Source

I'm looking for the magic command of creating a patch from the last commit made.

My workflow sometimes looks like this

vi some.txt
git add some.txt
git commit -m "some change"

and now I just want to write

git create-patch-from-last-commit-to-file SOME-PATCH0001.patch

but what should i put there instead of create-patch-from-last-commit-to-file?

Answer

Useless picture Useless · Feb 22, 2012

In general,

git format-patch -n HEAD^

(check help for the many options), although it's really for mailing them. For a single commit just

git show HEAD > some-patch0001.patch

will give you a useable patch.