Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

patch

People also ask

How do you make a patch of a commit?

In order to create Git patch file for a specific commit, use the “git format-patch” command with the “-1” option and the commit SHA. In order to get the commit SHA, you have to use the “git log” command and look for the corresponding commit SHA.


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.


Taking from @Useless answer, you can also use the general form with no parameters for the last commit and put it into a file with:

git format-patch HEAD^ --stdout > patchfile.patch

Or, being cleaner for windows users when carets have to be escaped by doubling them:

git format-patch HEAD~1 --stdout > patchfile.patch

another way, if have the commit id of that particular commit, you can use,

git format-patch -1 {commit-id}

You need the -p option to git log:

git log -1 -p --pretty='%b'

git format-patch -1

Does the job for me.