How to show git commit using number of commits since a tag

Try

git rev-list tag..HEAD --count

OR

git rev-list tag.. --count

They mean the same thing.


What you're asking for is impossible in the general case. The number of commits alone can't tell you anything if there are any merges in your history.

For example, given the following repo structure:

a - b - c - d - h
  \           /
    e - f - g

With a tag put on a, the outputs of git describe d and git describe g are identical save for the SHA1:

> git describe d
tag-3-ge8dca33
> git describe g
tag-3-g4fecc2e

That said, if you don't have a bunch of parallel branches going on at once, then you may be able to resolve a given commit number back to a single commit, but if you have even a single active side branch at the time of your tag then this may not work.

If you need reliable release numbers, you should stick to explicit tags.


If you are looking for the number of commits since the last tag, the following worked for me

git rev-list  `git rev-list --tags --no-walk --max-count=1`..HEAD --count

You can:

git log --oneline tag.. | wc -l

this will give you the number of commits

Tags:

Git