Some notes about patch workflows
Thus far, all previous workflows rely heavily on branches. And every developer needs their own public repo. However, it’s also possible to collaborate by sending directly your patch to the maintainer.
A patch file consists a single set of changes(i.e., a commit) that can be applied to any branch, in any order.
After you changed, staged and committed, you can create a patch from the new commit(s) using the git format-patch command.
$ git format-patch master
This created a file called
0001-<some-text>.patch which contents as below:
index 98e10a1..828dd1a 100644 --- a/pink.html +++ b/pink.html @@ -7,8 +7,7 @@ </head> <body> <h1 style="color: #F0F">The Pink Page</h1> - <p>Pink is <span style="color: #F0F">girly, - flirty and fun</span>!</p> + <p>Only <span style="color: #F0F">real men</span> wear pink!</p> <p><a href="index.html">Return to home page</a></p> </body>
While you don’t have to know the ins-and-outs to make use of patches, just know that a single patch file represents a complete commit. Since it’s a normal file and also an email, it’s much easier to pass around than a Git branch.
You can make several commits and the same amount patch files.
Now you can send them to the project maintainer.
There are two ways:
- Sending the patch file as an attachment to a normal email by hand.
- Using the convenient git send-email command, the guide can be refer to How to send patch files by git send-email.
After getting the patch files, using the git am command, we can use the patches to add the new commits to our repository.
$ git am 0001-<some-text>.patch
Then we can integrate the patches:
$ git checkout master $ git merge patch-integration $ git branch -d patch-integration $ git clean -f $ git push
Note: git clean to get rid of the patch files.
The final patch workflow resembles the following:
The patch workflow is just a simpler way to accept contributions than the previous workflows. Only the maintainer needs a public repository.
As a programmer, you’re most likely to use patches when you want to fix a bug in someone else’s project. After fixing it, you can send them a patch of the resulting commit. For this kind of one-time-fix, it’s much more convenient for you to generate a patch than to set up a public Git repository.
git format-patch <branch-name>
Create a patch for each commit contained in the current branch but not in
<branch-name>. You can also specify a commit ID instead of
git am [<] <patch-file>
Apply a patch to the current branch.
Ry’s Git Tutorial