Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

patch

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'.

like image 720
tirdadc Avatar asked Mar 06 '15 02:03

tirdadc


1 Answers

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

like image 188
Max Komarychev Avatar answered Sep 21 '22 12:09

Max Komarychev