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

如何获取单次Push的本地提交数量及上一个Push ID?能否按Push分组?

Hey there! Let's break down how to solve your Git-related questions clearly:

1. Get metrics from your last push

Number of changed files in the last push

To count how many files were modified in your most recent push, run this command:

git diff --name-only HEAD@{1} HEAD | wc -l

Here's what's happening:

  • HEAD@{1} refers to the state of your branch right before the last push (Git's reflog tracks these state changes)
  • git diff --name-only lists all files that differ between the pre-push and current branch states
  • wc -l counts the number of lines (each line corresponds to one changed file)

Number of local commits included in the last push

To find out how many local commits you bundled into one push, use:

git rev-list --count HEAD@{1}..HEAD

This command counts all commits that exist in your current branch state (HEAD) but weren't present before the last push (HEAD@{1}). As you noted, if this returns 3, the commit ID right before your last push would be HEAD^3 — though using HEAD@{1} directly to reference that pre-push commit is often more reliable, since it doesn't depend on counting manually.

2. Group commits by push operations

Git doesn't natively track "push" as a first-class object, but you can leverage the reflog (a local log of all branch state changes) to group commits by push actions. Here's how:

Run this to see every push action recorded locally:

git reflog --grep="push"

You'll get output like this:

abc1234 HEAD@{3}: push origin main: fast-forward
def5678 HEAD@{7}: push origin feature/xyz: forced update

Each entry marks the end state of a push, along with the target branch name.

Step 2: Group commits for a specific push

For any push entry (e.g., HEAD@{3}), you can view all commits included in that push by comparing it to the end state of the previous push. For example, if the prior push was at HEAD@{7}, run:

git log --oneline HEAD@{7}..HEAD@{3}

This will list all commits that were pushed in the action corresponding to HEAD@{3}.

Important note

The reflog is local-only — it only exists in your current Git repository. If you switch to a different clone of the repo, you won't see these push history entries. Also, forced pushes will still show up in the reflog, but you'll want to double-check commit ranges if you've rewritten branch history.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 07:56:41