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?
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.
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