0

I'm trying to get the total number of commits on a git repository, but the numbers seem wrong.

My first thought was to use:

git log --pretty=oneline | wc -l

Doing some research, I found a method that seems more appropriate for the task:

git rev-list --all --count

The thing is, even though they seem to accomplish the same thing, I'm getting different results. On a sample repository, the log command returns 1039 commits, whilst rev-list returns 1044 commits.

Why am I getting different results?

Andrejs Cainikovs
  • 27,428
  • 2
  • 75
  • 95
Fábio Queluci
  • 311
  • 1
  • 2
  • 15
  • It's `--pretty=oneline`, not *"online"*. `git log` displays only the commits that are accessible from the starting point you provide it (or from the current branch if no reference is provided). It doesn't show the branches that were not merged. It is not the tool you need. – axiac Oct 30 '17 at 15:35
  • git rev-list HEAD --count. -all will take all the refs from refs/ folder which would be all the remote and local branch commits. You would only want commits from current branch to count, hence, the difference in count. –  Oct 30 '17 at 15:36
  • 1
    Possible duplicate of [Count the number of commits on a Git branch](https://stackoverflow.com/questions/11657295/count-the-number-of-commits-on-a-git-branch) – Andrejs Cainikovs Oct 30 '17 at 15:39

1 Answers1

0

Solution:

> git rev-list --count HEAD

Explanation:

The above command allows you to count the number of commits for the branch you are on.

Technophobe01
  • 8,212
  • 3
  • 32
  • 59
Andrejs Cainikovs
  • 27,428
  • 2
  • 75
  • 95