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

如何获取HEAD开始到首个非本人提交前的连续提交哈希?

获取HEAD开始的连续本人提交哈希值

可以用git log结合自定义条件实现,直接用这条命令:

git log --author="你的用户名" --format="%h" --no-merges HEAD --not $(git log --author="^你的用户名" --format="%H" HEAD^..HEAD | head -n 1)^

命令逻辑拆解:

  • --author="你的用户名":筛选出你作为作者的提交,换成你的邮箱能更精准匹配
  • --format="%h":只输出提交的短哈希值
  • --no-merges:排除合并提交,避免干扰结果
  • 后半段--not $(...)^:自动找到首个非你提交的哈希值,排除它及之前的所有提交,只保留HEAD开始连续的你的提交

如果想要和示例里一致的顺序(从HEAD到HEAD~2),直接执行上面的命令即可;要是想从最早的连续提交开始输出,加个--reverse参数就行。

还有更简洁的写法,用git rev-list:

git rev-list --author="你的用户名" --max-count=$(git rev-list --author="^你的用户名" HEAD --count +1) HEAD

这条命令先算出从HEAD到首个非你提交的数量,再用--max-count获取对应数量的你的提交。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 22:42:39