Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get first and last commit from git from a user

Tags:

git

I was wondering how I could get my first an last git message commits from a git project?

My idea was to do a git log and use grep to catch the first and last row from a user, is there any elegant way of doing so?

like image 895
piggyback Avatar asked Feb 16 '26 23:02

piggyback


1 Answers

Use the --author flag with a regular expression that matches your name (which in practice might just be your name):

git log --author "Firstname Lastname"

You can simply use the -n option to get the last commit.

git log --author "Firstname Lastname" -n 1  # Last commit

The first commit is a little trickier; you can reverse the order with the --reverse flag, but it would be applied after -n 1, so you'll just have to post-process the output, for example,

git log --author "Firstname Lastname" --reverse | awk '/^commit/ { x+=1 } x>1 {exit}; {print}'

This assumes a chronological ordering. In the presence of multiple branches, there may not be a unique last commit, and it's possible that there isn't even a unique first commit.

like image 175
chepner Avatar answered Feb 18 '26 17:02

chepner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!