piggyback
piggyback

Reputation: 9264

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

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?

Upvotes: 3

Views: 731

Answers (1)

chepner
chepner

Reputation: 531265

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.

Upvotes: 3

Related Questions