Gilles Ruppert

a.k.a. elduderino78

Creating Patch Files With Git

Git has a built in way to create patches and Github has a great write up on this. The git format-patch command is useful if all your changes are committed and you want to create a patch of certain commits.

Sometimes however you have changes that you can’t or don’t want to commit for whatever reason. Git lets you easily create a standard patch file that you can apply on another clone or branch.

1
2
3
4
5
# To create the patch
git diff --no-prefix > path-to-patch/name-of-the-patch-file

# To apply the patch:
patch -p0 < path-to-patch/name-of-the-patch-file

If you have an existing git diff output that didn’t use the --no-prefix argument, you can just apply the patch like this:

1
patch -p1 < path-to-patch/name-of-the-patch-file

Voila.