Simplest way of creating a patch in git
This will also works as a reminder for me. Perfec explanation can be found in https://ariejan.net/2009/10/26/how-to-create-and-apply-a-patch-with-git/
Hereby the smallest number of steps I've found to be necessary to create a patch out of a single git commit in a repository.
Let's assume I want to create a patch out of a commit hash 12345 with a name mypatch.patch.
From the top level directory or the project:
git format-patch -1 <commit> --stdout > mypatch.patch
This will create a file name mypatch.patch.
git apply --stat mypatch.patch
Show which files are affected by the patch without applying those changes.
git apply --check mypatch.patch
Test the patch for errors before applying it.
git am --signoff < mypatch.patch
Applys the patch and adds an explanatory message to commit history so that that commit was a patched one.
Written by Esteban
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
khasinski
591.1K
dmichaelavila
500.4K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#