我需要一种安全的方法来获得node.js中最新提交的git描述。
git commit -m "some message" -m "this is the description"
我正在使用require('child_process').execSync('git log -1').toString();
其中产出:
commit f8f42hash5556666b3c518e3hash294b62e88888
Author: Developer Name <email@email.com>
Date: Tue Jun 28 08:10:09 2022 +0200
some message
this is the description我知道可以添加一些-format='????',但是按照这个指南;https://devhints.io/git-log-format似乎找不到给我描述的选项.
编辑:我看到了关于描述和消息被视为oine的评论,这让我感到惊讶,因为gitlabs界面实际上可以区分不同之处,我也看到它们在GUI git管理器(可能是gitlabs或vscode插件)中作为separetae字段。
下面是它在gitlab中的外观(

发布于 2022-07-04 12:12:10
您可以得到这样的消息:git log -1 --format='%b'
它将返回:
some message
this is the description然后可以使用JavaScript提取第二行文本。
发布于 2022-07-04 12:21:01
注意,正确的选项是--pretty,根据Git日志文档!
对我来说,你应该使用这个,它对我有效:git log -1 --pretty="format:%s"。
https://stackoverflow.com/questions/72856482
复制相似问题