Create Patch Files From Multiple Commits In Git

As i am working on some open source project with the community, it is best to send the file patches instead of merge request. And couple projects are not using Github or Gitlab. And the team leader need us to send the patch file instead of push them right away to the main git repository. The reason for testing and staging purpose.

Fortunately git could export those commits into patches with this command:

git format-patch -x

where -x means how many commits back from the current head and it has to be integer.

For example if i want to generate patch for 10 last commits:

git format-patch -10

The above example will generate 10 file patches, this will cause a problem for the team leader, because he need to apply the patches one by one. You can squashed those patches into 1 single file patch. See the code below:

git format-patch -x --stdout > patch-ddmmyyy.patch

From the format above it means all those generated patches will compress into 1 output file. And for the standard i usually add the date for the file, so i know when i generate it.

Note: The generated patches also work with subversion (svn).

That’s all, any question please let me know.

Comments

  1. danielramirezfas says:

    I think you are missing the –stdout before the redirection 😀 Your example redirects a list of the patch names, not the content!

  2. louielutw says:

    Thanks, this helps!

  3. Leo says:

    Hello there ,
    how could I get the patch from specific period of time or specific node

  4. Great tip! Thx!

Give me your feedback

This site uses Akismet to reduce spam. Learn how your comment data is processed.