How to Generate Git Patch for Specific Commit Id ?

By default, “git format-patch COMMIT_ID” command, generates all the patches from most recent till the commit id mentioned with git format-patch.

Let’s consider following git log as an example,

In this, if we give a default git format patch command for a commit id “f96a4d72ebcbbf99ed3c0b9495c87ab025dcebdf” (2) then, it will generate all patches for commits (6), (5), (4) and (3)

But what if we need only one patch for commit id (2) , then we can use below command to generate the single patch as,

$ git format-patch -1 f96a4d72ebcbbf99ed3c0b9495c87ab025dcebdf

So in general, if we want to take single patch for specific commit id, we can use following command,

$ git format-patch -1 COMMIT_ID

Leave a Comment