Git: Get first line of commit message from shell
You should have an empty line after the first line to separate title from body of the message, like:
this is my commit message title
some details
go here
yadda yadda
If you did that, then this should work for you:
$ git log --oneline -n 1 HEAD
d53468c this is my commit message title
But say you didn’t. So, for the commit message:
getting one line git commit msg
second
third line
fifth line
You get:
$ git log --oneline -n 1 HEAD
c43b68c getting one line git commit msg second third line
Or, if you don’t want the hash (you want the message only):
$ git log --oneline --format=%B -n 1 HEAD
getting one line git commit msg
second
third line
fifth line
But, ladies and gentlemen, if you just want the first line of the message, do:
$ git log --oneline --format=%B -n 1 HEAD | head -n 1
getting one line git commit msg
Leave a Comment