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.

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:

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

Voila.

About elduderino78

I'm a front-end developer working in the bowels of BBC Worldwide & focusing on POSH (HTML), CSS, JavaScript, Ajax, accessibility & usability
This entry was posted in Development, Tools and tagged , . Bookmark the permalink.

One Response to Creating patch files with git

  1. mohammad says:

    thank you for web site

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">