繁体   English   中英

How do I get the git commit description in node?

[英]How do I get the git commit description in node?

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@email.com>
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; https://devhints.io/git-log-format I can't seem to find a option that gives me the description...

Edit: I see comments about description and message being treated as oine thing, which surprises me, because gitlabs interface can in fact tell the difference, I have also seen them as separetae fields in som GUI git manager (maybe git kraken or a vscode plugin)..

Here's how it looks in gitlab (--skipSmokeTest is the description) enter image description here

你可以得到这样的消息: git log -1 --format='%b'
它将返回:

 some message this is the description

然后您可以使用 JavaScript 提取第二行文本。

请注意,根据Git 日志文档,正确的选项是--pretty

对我来说,你应该使用它,它对我有用: git log -1 --pretty="format:%s"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM