Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting all commits from HEAD up to a different author

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.

like image 240
FinenessSedan Avatar asked Sep 01 '25 04:09

FinenessSedan


1 Answers

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 }
'
like image 97
jthill Avatar answered Sep 02 '25 18:09

jthill