git 特定作者的格式补丁 X..Y

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

我想知道您是否可以为一个范围生成补丁,但仅限于特定作者的提交,就像您对 git log --author='bob' 所做的那样。

是的,有可能。

根据 git format-patch 上的 reference 它接受 <revision range>

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

详情可以在 reference 中找到,但我们只需要这个:

^!, 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).

所以你需要:

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

git log X..Y --author='<AUTHOR>' --format="%H" 产生 40 位 sha1 和格式的输出。

sed 's/$/^!/g' 添加 ^!在每行的末尾

xargs -I{} git format-patch {} 每行 git format-patch 只运行