14

I want to create a metric in my project that measures how long does a commit take from its creation till to get into the master branch.

Is it possible? It looks like for fast-forwarded commits I can't get this info from the git log.

If I can get a snapshot of the repository X days ago, maybe I can calculate it. Another option is to get a log that registers when a branch HEAD was modified.

Update: If you create an annotated tag at each release, you can just see the date of the tag that included the commit. Here is how to list the commits included in a tag

neves
  • 33,186
  • 27
  • 159
  • 192
  • using git show --pretty=fuller SHA1 you could look at author date and commit date; BTW when using gerrit, a commit-id is added to track commits between branches, could maybe be done the same way in your project – OznOg Nov 21 '18 at 18:43
  • See this helps: https://stackoverflow.com/questions/10585874/how-do-you-find-who-merged-a-git-commit-into-a-branch and https://stackoverflow.com/questions/42897660/determine-when-branch-was-merged-into-another – Rishabh Agarwal Nov 21 '18 at 18:54

1 Answers1

7

It is not easy, considering the commit itself does not know in which branch it is.
It does not keep track of branch "events" which would mention it was created in branch X, and then merge (possibly fast-forward) in branch Y.

Only git reflog registers HEAD changes, but it is limited in time.

As mentioned by the OP, you need to add a metadata (like an annotated tag, but you could also consider a git notes) in order to memorize the information you need.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Since there is no permanent register of changing the read of a branch, the really feasible solution is to create an annotated tag, and see the [commits in between](https://stackoverflow.com/questions/5863426/get-commit-list-between-tags-in-git) – neves Nov 22 '18 at 14:39
  • @neves I afre, and have included your comment in the answer for more visibility. – VonC Nov 22 '18 at 16:52