Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / DevOps / Git

Set and Run gitstats on Your Windows Machine

4.92/5 (8 votes)
17 Oct 2014CPOL4 min read 29.4K  
Help you set and run gitstats on your windows

Introduction

GitStats is a statistics generator for git (a distributed revision control system) repositories. It examines the repository and produces some interesting statistics from the history of it. Currently HTML is the only output format.

Background

I've tried to run this a couple of times, for no avail. There wasn't a straight up tutorial I could find on how to do it, so having wasted the time to do it, I hope this will save others some time.

Requirements

There are several things you'll need in order to make this work.

1. Gitstats

You can find the sourceforge project page here, and the github code is sitting here.

Get the code, and simply unzip it into any folder on your computer.

Once you did this, go into the folder and rename the file "gitstats" to "gitstats.py".

2. Git

I'm assuming you have this installed, since otherwise, I doubt you'll be having any git projects to be running this on :).

According to the documentation, you should have a git version >= 1.5.2.4. I'm currently using 1.9.2 . If you're having an older version, it's time to upgrade :).

(To check the git version you are running, just type "git --version" in the command prompt.:

Image 1

3. Python

Head to the python homepage, and select the one that makes you happy, as long as you choose the 2.7.8 (Yep, I'm aware of the contradiction).

The documentation claims you need python >= 2.6 , but it seems this is not compatible with python 3. So ... pick the 2.7.8. I've got the windows installer, and just ran it. While you do it, make sure you choose the option to add python to path if you wan't to make your life easier.

3.1 Rapid Environment Editor (RapidEE)

Once you're done, you want to make sure you LOG OFF and back in, so the changes to the path are applied.

I suggest installing the above program (RapidEE), which is free, and lets you easily see what paths you have in your registry, and add/edit them if you want. Here's a screenshot of what it looks like:

Image 2

4. Gnuplot

Gnu what ? Gnuplot !

Gnuplot is a free plotting library that makes pretty graphs. Head to their Homepage to get the latest version (4.6.5 at the time of writing, with version 5 supposedly coming out soon). According to documentation, any version >= 4.0.0 should work.

This seems to be all the hype amongst the academia people, graph nerds, and seemingly linux people who just seem to have it. It's pretty easy to pick if you want to, but for this tutorial, all you need is to have it installed.

Putting It All Together

Assuming you've followed the above steps, all you need is to go ahead and get your pretty stats and graphics.

Fire up a command prompt and type in "python". You should see a prompt telling you which version you're running, and get a new command prompt that looks like : ">>>" . Hit Ctrl+Z, Enter, to get out of it.

This is just to make sure that python is installed and can be found by the system. It should look like this:

Image 3

If that works, you'll have to navigate into the folder where you've installed gitstats. For this example, I'll use:

  • Gitstats sits in: "C:\Users\xxx\Desktop\gitstats"
  • The git repository I want to clone: "C:\Users\xxx\Desktop\AwesomeProject"
  • The output directory: "D:\My Stats\Html"

Whichever paths you're using, make sure you have write permissions to them, and that they exist.

  1. So, in your command prompt, enter:
    cd "C:\Users\xxx\Desktop\gitstats". 

    The quotes are used just in case you have a white space in your path, for example: "C:\Some Folder\gitstas" will not work without the quotes.

  2. The command is python gitstats.py source_of_git target_of_html and in our example will look like:
    python gitstats.py "C:\Users\xxx\Desktop\AwesomeProject" "D:\My Stats\Html"

    Make sure you point to the folder which holds the .git folder inside of it, and not to the .git folder directly, or any of the branches underneath it. Also, the output directory should exist before you run this.

  3. Open your output directory, and you'll see a whole bunch of files. Simply double click on the one called: index.html and it should open in your default browser. Note that they suggest "any sensible browser", so if you're using netscape 3, YMMV.

     

    You should see something like:

    Image 4

Clicking on the different buttons will show you the stats and graphs.

Congratulations, you can go back to being productive.

Troubleshooting

Some of the things I've encountered where:

Problem: python runs into an infinite loop of errors.

Solution: Renaming "gitstats" to "gitstats.py" seems to help.

Problem : Python complains about a line which includes "wc -l".

Solution: I've added the path of the git binaries which include the wc command to my path, which seems to have solved it.

Wrapping up

That's it really. You should be able to see some basic stats and graphs and be the envy of your friends and the life of the party from this day on.

I hope you'll find this helpful, and that it'll save you some time.

If it does, please vote and feel free to leave a comment.

History

  • 18th October, 2014 - Initial release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)