I don't know how to do it in one line, but here's a simple bash script:
#!/usr/bin/env bash
email="$1"
upto="$(awk '{print NR-1 " " $0}' <(git log --pretty=format:'%ae' HEAD) | grep $email | head -n 1 | awk '{ print $1 }')"
from="$(awk '{print NR-1 " " $0}' <(git log --pretty=format:'%ae' HEAD~$upto) | grep -v $email | head -n 1 | awk '{ print $1 }')"
git log HEAD~$from..HEAD~$upto
Explanation
Find the first commit from the given email
First, list all the commits reachable by HEAD
printing only the author's email:
git log --pretty=format:'%ae' HEAD
Then, prepend the line number, starting by 0
, to each of the commits returned from the command above:
awk '{print NR-1 " " $0}' <(git log --pretty=format:'%ae' HEAD)
Then, select only the commits by the given email
:
awk '{print NR-1 " " $0}' <(git log --pretty=format:'%ae' HEAD) | grep $email
Then, get the first commit by the given email
:
awk '{print NR-1 " " $0}' <(git log --pretty=format:'%ae' HEAD) | grep $email | head -n 1
Then, get the line number, which represents the number of commits from HEAD
:
awk '{print NR-1 " " $0}' <(git log --pretty=format:'%ae' HEAD) | grep $email | head -n 1 | awk '{ print $1 }'
Finally, store it into the $upto
variable, because it's the top of the range:
upto="$(awk '{print NR-1 " " $0}' <(git log --pretty=format:'%ae' HEAD) | grep $email | head -n 1 | awk '{ print $1 }')"
Find the first commit that isn't from the given email
and it's after it's first commit
The command is similar with two differences:
- We need to find commits reachable from
HEAD~$from
.
- We need to select the first commit that isn't from the given
email
.
So, the command, with the differences highlighted, is:
from="$(awk '{print NR-1 " " $0}' <(git log --pretty=format:'%ae' HEAD~$upto) | grep -v $email | head -n 1 | awk '{ print $1 }')"
^^^^^^^^^^ ^^
Printing the log
Finally, to print the log of commits from the first commit that isn't by the given email
to the first commit that is from the given email
:
git log HEAD~$from..HEAD~$upto
Edit: Although, as suggested in a comment, using branches and doing a git log master..HEAD
is highly preferable over this solution.