vmasanas
vmasanas

Reputation: 515

List Git commits count per tag

Is there a way to get a nicely formated listing of tags and commits per tag? The output I'm looking for would be something like:

TAG - DATE - Num of commits
------------------------------
v1.1.1 - 10/MAR/2020  -  12
v1.1.2 - 15/MAR/2020  -  15
...

Upvotes: 0

Views: 255

Answers (1)

LeGEC
LeGEC

Reputation: 51850

I don't know of a one shot command to do this. However :

  • You can list tags starting with v in version order :
git tag --list v* --sort="v:refname"
  • You can count the number of commits between two points :
git rev-list --count A..B

# example :
git rev-list --count v1.1.1..v1.1.2
  • If your tags are lightweight tags placed on commits, you can get the date of the underlying commit :
# %ad for author date, %cd for committer date
$ git log -1 --format="%cd" v1.1.2

# you can tell git log to format the date using the --date option
$ git log -1 --format="%cd" v1.1.2

# you can tell git log to format the date using the --date option
$ git log -1 --date=short --format="%cd" v1.1.2
# you can use 'format:...' to specify a format for strftime() :
$ git log -1 --date="format:%Y/%b/%d" --format="%cd" v1.1.2

More details on the --date option (full doc here) :

--date=short shows only the date, but not the time, in YYYY-MM-DD format.

[...]

--date=format:... feeds the format ... to your system strftime


Using these bricks, you can write a script that produces the output you want.

Upvotes: 1

Related Questions