git format-patch X..Y for a specific author

Issue

I was wondering if you can generate patches for a range but only limit to commits from a specific author, the way you do with git log --author='bob'.

Solution

Yes, it is possible.

According to reference on git format-patch it accepts <revision range>

Generic expression (see “SPECIFYING REVISIONS”
section in gitrevisions(7)) means the commits in the specified range.

Details may be found in the reference but we only need this one:

^!, e.g. HEAD^!

A suffix ^ followed by an exclamation mark is the same as giving commit and then all its parents prefixed with ^ to exclude them
(and their ancestors).

So you’ll need:

git log X..Y --author='<AUTHOR>' --format="%H" | sed 's/$/^!/g' | xargs -I{} git format-patch {}

git log X..Y --author='<AUTHOR>' --format="%H" produces output in format of 40-digit sha1 sums.

sed 's/$/^!/g' adds ^! at the end of each line

xargs -I{} git format-patch {} just runs git format-patch with each line

Answered By – Max Komarychev

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published