In my case, I want to be able to get a list of commit hashes of all commits from HEAD
where I am the author, i.e. retuning all commits until there is a parent commit where I am not the author. e.g. in the following commit list
HEAD - abc - Me
HEAD~1 - efg - Me
HEAD~2 - hij - Me
HEAD~3 - klm - Someone else
HEAD~4 - nmo - Me
I only want abc
, efg
and hij
to be returned. I am able to assume HEAD
is authored by me in my use case.
I tried looking into git rev-parse
, but it can only get all or a certain number of commits where I am the author, not all sequential commits until there is a commit where I am not the author.
To do this with a single pipeline, no incessant lookups,
git rev-list --pretty=%ae%x0a%s @ \
| awk ' { commit=$2; getline; email=$0; getline; subject=$0
if ( email == me ) print subject; else exit }
' me='[email protected]' # for example
edit: or for just the sequence of commit hashes with the same author as the tip commit,
git rev-list --pretty=%ae @ \
| awk '{ commit=$2; getline; email=$0
if ( email != last ) if ( !last ) last=email; else exit
print commit }
'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With