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

咨询Git Log标签名称占位符:格式化输出含标签名并保存至文件

Git Log标签名称占位符说明

在git log的自定义格式化参数中,用于表示提交关联标签的占位符有两个常用选项:

  • %d:显示该提交关联的所有引用(包含标签、分支、远程分支等),输出会用括号包裹,格式类似(tag: v1.0, master)
  • %D:与%d功能一致,但会输出完整的引用路径(比如refs/tags/v1.0)

如果希望仅保留标签信息并简化输出,可以搭配--decorate=short参数使用%d,修改后的命令示例:

git --no-pager log --oneline --format="%h, %ad, %cn, %s, %d" --date=format:"%Y-%m" --decorate=short > gitlog.txt

如果需要更纯净的标签名称(去除括号、tag:前缀等冗余内容),可以通过管道结合文本处理工具过滤,示例:

git --no-pager log --oneline --format="%h, %ad, %cn, %s, %d" --date=format:"%Y-%m" --decorate=short | sed 's/.*tag: \([^,)]*\).*/\1/; s/,$//' > gitlog.txt

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 16:17:04