Home > Enterprise >  How do I get the git commit description in node?
How do I get the git commit description in node?

Time:07-05

I need a safe consitent way to get the git description of latest commit in node.js

git commit -m "some message" -m "this is the description"

I am using require('child_process').execSync('git log -1').toString();

which outputs:

commit f8f42hash5556666b3c518e3hash294b62e88888
Author: Developer Name <[email protected]>
Date:   Tue Jun 28 08:10:09 2022  0200

    some message

    this is the description

And I know that it is possible to add some -format='????' but following this guide; enter image description here

CodePudding user response:

You can get the message like this: git log -1 --format='%b'
It will return:

some message

this is the description

Then you can extract the second line of text using JavaScript.

CodePudding user response:

Beware the correct option is --pretty according to the Git log doc !

For me, you should use this, it works for me: git log -1 --pretty="format:%s".

  • Related