458

I'm looking for some good tools/scripts that allow me to generate a few statistics from a git repository. I've seen this feature on some code hosting sites, and they contained information like...

  • commits per author
  • commits per day/week/year/etc.
  • lines of code over time
  • graphs
  • ... much more

Basically I just want to get an idea how much my project grows over time, which developer commits most code, and so on.

1
  • 3
    If you cannot install gitstats, you can at least get the number of lines of code by author using basic git commands: git ls-files | while read f; do git blame -w -M -C -C --line-porcelain "$f" | grep -I '^author '; done | sort -f | uniq -ic | sort -n --reverse
    – hartmut
    Dec 3, 2020 at 12:12

10 Answers 10

355

commits per author

git shortlog -s -n 
6
  • 91
    exclude merges: git shortlog -sn --no-merges
    – doblak
    Feb 5, 2015 at 6:42
  • 9
    e flag gives you committers email address git shortlog -sne Jun 22, 2016 at 2:30
  • 3
    Personally I am more interested in how many lines each person was the last one to touch, or total number of lines changed per person. Commits per author is also interesting though. Aug 17, 2018 at 1:05
  • 22
    git shortlog -s -n --since "DEC 31 2017" if you want to filter since a given date. Great for annual reviews ;) Dec 14, 2018 at 21:47
  • 5
    @EnekoAlonso I recommend against using such metrics to measure developer performance. You will likely see false positives masking poor development practices, while some of the best developers will go unnoticed. There is no correlation between number of commits and developer performance, aside from 0 or way, way, way too many.
    – Todd
    Mar 4, 2020 at 18:45
304

Beside GitStats (git history statistics generator) mentioned by xyld, written in Python and requiring Gnuplot for graphs, there is also

10
82

I'm doing a git repository statistics generator in ruby, it's called git_stats.

You can find examples generated for some repositories on project page.

Here is a list of what it can do:

  • General statistics
    • Total files (text and binary)
    • Total lines (added and deleted)
    • Total commits
    • Authors
  • Activity (total and per author)
    • Commits by date
    • Commits by hour of day
    • Commits by day of week
    • Commits by hour of week
    • Commits by month of year
    • Commits by year
    • Commits by year and month
  • Authors
    • Commits by author
    • Lines added by author
    • Lines deleted by author
    • Lines changed by author
  • Files and lines
    • By date
    • By extension

If you have any idea what to add or improve please let me know, I would appreciate any feedback.

3
  • Object count and repo size would be nice additions to the General statistics
    – pdeschen
    Jan 11, 2013 at 20:29
  • Commits by: Day of the month. Are they more active at month end?
    – Ole Tange
    Jun 27, 2017 at 16:49
  • Awesome thing! Could you also add the statistics about the issues and the pull requests?
    – timmey
    Dec 8, 2020 at 17:14
48

I tried http://gitstats.sourceforge.net/, starts are very interesting.

Once git clone git://repo.or.cz/gitstats.git is done, go to that folder and say gitstats <git repo location> <report output folder> (create a new folder for report as this generates lots of files)

Here is a quick list of stats from this:

  • activity
    • hour of the day
    • day of week
  • authors
    • List of Authors
    • Author of Month
    • Author of Year
  • files
    • File count by date
    • Extensions
  • lines
    • Lines of Code
  • tags
6
19

git-bars can show you "commits per day/week/year/etc".

You can install it with pip install git-bars (cf. https://github.com/knadh/git-bars)

The output looks like this:

$ git-bars -p month
370 commits over 19 month(s)
2019-10  7    ▀▀▀▀▀▀
2019-09  36   ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
2019-08  7    ▀▀▀▀▀▀
2019-07  10   ▀▀▀▀▀▀▀▀
2019-05  4    ▀▀▀
2019-04  2    ▀
2019-03  28   ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
2019-02  32   ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
2019-01  16   ▀▀▀▀▀▀▀▀▀▀▀▀▀▀
2018-12  41   ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
2018-11  52   ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
2018-10  57   ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
2018-09  37   ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
2018-08  17   ▀▀▀▀▀▀▀▀▀▀▀▀▀▀
2018-07  1    
2018-04  7    ▀▀▀▀▀▀
2018-03  12   ▀▀▀▀▀▀▀▀▀▀
2018-02  2    ▀
2016-01  2    ▀
13

repostat is an enhanced fork of gitstats tool.

I'm not sure if it's in any way related to the project with the same name on pypi, so your best bet is to download the latest release from GitHub and install it in your Python environment.

As of November 2019, I was able to use v1.2.0 under Windows 7, after making gnuplot available in PATH.


usage: repostat [-h] [-v] [-c CONFIG_FILE] [--no-browser] [--copy-assets]
                git_repo output_path

Git repository desktop analyzer. Analyze and generate git statistics in HTML
format

positional arguments:
git_repo              Path to git repository
output_path           Path to an output directory

optional arguments:
-h, --help            show this help message and exit
-v, --version         show program's version number and exit
-c CONFIG_FILE, --config-file CONFIG_FILE
                        Configuration file path
--no-browser          Do not open report in browser
--copy-assets         Copy assets (images, css, etc.) into report folder
                        (report becomes relocatable)
1
  • 2
    This worked great for me too in November 2020, version 2.2.0, on Windows 10 with Python 3.8 (3.9 is failing at the moment). Nov 19, 2020 at 12:31
10

Just want to add gitqlite into the mix of answers here, which is a command-line tool that enables execution of SQL queries on git data, such as SELECT * FROM commits WHERE author_name = 'foo' etc.

Full disclosure, I'm a creator/maintainer of the project!

6

If your project is on GitHub, you now (April 2013) have Pulse (see "Get up to speed with Pulse"):

It is more limited, and won't display all the stats you might need, but is readily available for any GitHub project.

Pulse is a great way to discover recent activity on projects.
Pulse will show you who has been actively committing and what has changed in a project's default branch:

Pulse

You can find the link to the left of the nav bar.

Link

Note that there isn't (yet) an API to extract that information.

0
4

And if you prefer hosted solution, you should check out Open Hub (formerly Ohloh.net). It is nice, but don't expect large statistics.

3
  • If you are ok with a bit clumsy interface and updates on a ~24h basis, ohlohis good choice, otherwise I'd go for DIY approach.
    – drahnr
    Apr 24, 2012 at 9:58
  • 2
    ohloh is cool, but it only works on public repos. Also, it works with lots of VCSs, not just git.
    – naught101
    Jun 15, 2012 at 1:53
  • @naught101 You might try gitential.com as an alternative. It's in beta, but measures and visualizes coding hours, productivity for projects, teams, repos and individual developers.
    – kszucs
    Oct 3, 2017 at 12:01
4

Just yesterday I've added my git-analytics docker-compose file, which builds up several containers to start analyzing multiple git repositories against each other.

It is able to show you commit statistics over time about the author and also several diff statistics.

You can use the provided angular client and also kibana to visualize the statistics.

https://github.com/alexejsailer/git-analytics-docker

It will be improved over time.

Angular Client Screenshot

Angular Client Screenshot

Kibana Client Screenshot

Kibana Client Screenshot]

Not the answer you're looking for? Browse other questions tagged or ask your own question.