0

From Count the number of commits on a Git branch I have learned, how to get the Number of commits on a single branch since my Tag was created. My Question now is how I can get the absolute difference since the Tag was created across all Branches in my Repository?

For Example I have my branch master, branches feature/somefeature1, feature/somefeature2, release/somerelease, and my Tag refs/tags/sometag1.

where I want to sum up all commits since refs/tags/sometag1 was created.

r4d1um
  • 528
  • 1
  • 9
  • 32
  • What happens if the tag does not appear in the history of a certain branch, e.g. some branch split from `master` before the tag got created? – Tim Biegeleisen Oct 24 '17 at 06:11
  • Off the top of my head, you could use `git branch --contains ` to identify all branches having this tag, then use your current solution to get the count. This could be done from a script (@VonC are you reading this?). – Tim Biegeleisen Oct 24 '17 at 06:13

1 Answers1

2

Assuming that you are talking about local branches you can use rev-list to do exactly the same count:

git rev-list --count --branches ^refs/tags/sometag1

All the same options apply as in the linked question, so you can also pass things like --no-merges if required.

Note that this interprets "since" in a topological or ancestry sense so if you have an old branch that was never merged, those unmerged commits would count towards the total.

For a strictly commit date based solution you could do something like:

git rev-list --count --branches --since="$(git show -s --format=%ct refs/tags/sometag1^{})"
CB Bailey
  • 755,051
  • 104
  • 632
  • 656