Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grep functionality with Git Log command

Tags:

git

gerrit

I need to use the Git log command to extract Commit Id, commit subject where commit-body contains a specific word. I also need to print only those lines from the commit body that contain that word.

Using the command below, I am able to obtain relevant commit Id's and subject, but I can't see the lines from commit body containing the word 'CRs-Fixed'.

git log --pretty=format:"%H,%s" AU_1..AU2 --no-merges --grep='CRs-Fixed'

And If I do git log --pretty=format:"%H,%s,%b" AU_1..AU2 --no-merges --grep='CRs-Fixed', I get the entire commit body- which I don't need.

Any suggestions on how to get only the desired information?

like image 405
user1429246 Avatar asked Jun 26 '26 04:06

user1429246


1 Answers

Tag your header lines as keepers:

git log --pretty=format:$'\001%H\n\001%s\n%b' --grep='CRs-Fixed' \
| sed $'/^\001\\|Crs-Fixed/s/^\001//'

like image 131
jthill Avatar answered Jun 29 '26 02:06

jthill



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!