Create and Apply Git Patches: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Git Concepts * <tt>git format-patch</tt> =Overview= <code>git format-patch</code> exports the content of each commit into a "patch" that can then be applied with <code>git am</code> or <code>git apply</code>.")
 
 
(3 intermediate revisions by the same user not shown)
Line 3: Line 3:
* <tt>[[git format-patch]]</tt>
* <tt>[[git format-patch]]</tt>
=Overview=
=Overview=
<code>git format-patch</code> exports the content of each commit into a "patch" that can then be applied with <code>[[git am]]</code> or <code>[[git apply]]</code>.
 
Patches can be created with <code>[[git format-patch]]</code> and applied with <code>[[git am]]</code> or <code>[[git apply]]</code>.
 
=Create the Patch=
 
Specify how many commits from head to include in the patch:
 
<syntaxhighlight lang='bash'>
git format-patch -<n> <reference-sha-1> --stdout > ./file.patch
</syntaxhighlight>
 
<syntaxhighlight lang='bash'>
git format-patch -1 HEAD --stdout > ./file.patch
</syntaxhighlight>
 
=Apply the Patch=
 
<syntaxhighlight lang='bash'>
git am < ./file.patch
</syntaxhighlight>

Latest revision as of 21:51, 16 January 2024

Internal

Overview

Patches can be created with git format-patch and applied with git am or git apply.

Create the Patch

Specify how many commits from head to include in the patch:

git format-patch -<n> <reference-sha-1> --stdout > ./file.patch
git format-patch -1 HEAD --stdout > ./file.patch

Apply the Patch

git am < ./file.patch