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

git for-each-ref用--format指定多字段无输出,单字段正常求排查

Git for-each-ref 指定多字段无输出的解决方法

问题核心:使用git for-each-ref指定单个字段(如%(committerdate)或%(refname))时输出正常,但同时指定多个字段时无任何输出,例如执行以下命令无结果:

λ git for-each-ref --format='%(committerdate) %(refname)' --sort=committerdate

问题原因

你当前使用的是Windows类终端(从提示符λ判断为Cmder/CMD环境),这类终端对单引号'的解析逻辑和类Unix终端不同,导致Git无法正确识别你传入的多字段格式字符串,进而无法生成输出。

解决方法

将格式字符串的单引号替换为双引号",Windows终端能正确解析双引号包裹的含空格字符串:

λ git for-each-ref --format="%(committerdate) %(refname)" --sort=committerdate

如果需要每条记录单独换行,可在格式字符串末尾添加%n(换行符),可读性更强:

λ git for-each-ref --format="%(committerdate) %(refname)%n" --sort=committerdate

执行上述修改后的命令后,就能正常同时输出提交者日期和引用名称,条目数量与单字段查询时一致。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 05:01:06