Count the number of commits on a Git branch

后端 未结 12 1106
[愿得一人]
[愿得一人] 2020-12-02 04:28

I found this answer already: Number of commits on branch in git but that assumes that the branch was created from master.

How can I count the number of commits along

12条回答
  •  星月不相逢
    2020-12-02 05:06

    It might require a relatively recent version of Git, but this works well for me:

    git rev-list --count develop..HEAD
    

    This gives me an exact count of commits in the current branch having its base on master.

    The command in Peter's answer, git rev-list --count HEAD ^develop includes many more commits, 678 vs 97 on my current project.

    My commit history is linear on this branch, so YMMV, but it gives me the exact answer I wanted, which is "How many commits have I added so far on this feature branch?".

提交回复
热议问题