You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何仅生成git COMMIT_EDITMSG格式内容并输出至标准输出或自定义文件?

生成Git提交模板内容的跨平台命令

要获取git commit不带-m参数时编辑器中生成的带#前缀的注释内容(仅执行内容生成步骤,不打开编辑器、不修改文件、不完成提交),可以使用以下跨平台命令:

输出到标准输出(STDOUT)

Linux/macOS

echo -n | git commit -F - --dry-run

Windows(PowerShell)

"" | git commit -F - --dry-run

Windows(CMD)

echo. | git commit -F - --dry-run

输出到自定义文件

Linux/macOS

echo -n | git commit -F - --dry-run > commit-template.txt

Windows(PowerShell)

"" | git commit -F - --dry-run | Out-File commit-template.txt -Encoding utf8

Windows(CMD)

echo. | git commit -F - --dry-run > commit-template.txt

这些命令通过向git commit传入空的提交信息(通过-F -读取标准输入的空内容),并配合--dry-run参数(仅模拟提交流程,不实际执行任何修改操作),触发Git生成与git commit不带-m时编辑器内完全一致的模板内容,包含带#前缀的工作目录状态说明和提交提示信息。

内容的提问来源于stack exchange,提问作者LaVache

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 12:16:14