How can I generate a Git patch for a specific commit?

Viewed 876001

I need to write a script that creates patches for a list of SHA-1 commit numbers.

I tried using git format-patch <the SHA1>, but that generated a patch for each commit since that SHA-1 value. After a few hundred patches were generated, I had to kill the process.

Is there a way to generate a patch only for the specific SHA-1 value?

11 Answers

Create a git patch using commit-id

$ git format-patch -1 commit-id

This command create patch with following file name

0001-commit-message.patch

To apply the patch:

$ git am 0001-commit-message.patch

If you just want diff the specified file, you can use:

git diff master 766eceb -- connections/ > 000-mysql-connector.patch

With my Mercurial background I was going to use:

git log --patch -1 $ID > $file

But I am considering using git format-patch -1 $ID now.

Related