Backend Development 8 min read

Analyzing Git Repository Commit Statistics with libgit2sharp, .NET Core, and PowerBI

This article describes how to collect, process, and visualize Git commit data—including hashes, authors, dates, messages, and line changes—by using native git commands, the libgit2sharp .NET library, a custom cross‑platform CLI tool, and PowerBI dashboards for comprehensive reporting.

DevOps
DevOps
DevOps
Analyzing Git Repository Commit Statistics with libgit2sharp, .NET Core, and PowerBI

In early March 2020, after the company shifted to remote work due to the pandemic, a product manager requested statistical analysis of commit information across multiple project Git repositories.

The author first explored the built‑in git log command, which outputs commit hash, author name and email, commit message, and date (including timezone). To also capture the number of lines added or deleted per commit, the git log --shortstat option was examined.

By combining a custom pretty‑format string with tr , an elaborate one‑liner was built to produce CSV‑ready output:

git log --all --pretty="%x40%h%x2C%an%x2C%ad%x2C%\"%s%\"%x2C" --shortstat | tr "\n" " " | tr "@" "\n"

Although functional, this shell‑centric solution required the tr utility, making it unsuitable for Windows environments and hard to maintain or extend to JSON output.

Research led to libgit2sharp , a .NET wrapper around the libgit2 engine. Using its API, a simple command‑line program was written to enumerate commits, extract hash, author, message, date, and line‑change statistics, and serialize the results to any format (CSV, JSON, XML). The core code is:

using (var repo = new Repository(workdir))
{
Console.WriteLine("all commit count:" + repo.Commits.Count());
foreach (Commit commit in repo.Commits)
{
var commitDto = new GitCommitLogDto
{
CommitHash = commit.Sha,
AuthorName = commit.Author.Name,
AuthorEmail = commit.Author.Email,
MessageShort = commit.MessageShort,
AuthorDate = commit.Author.When.DateTime,
};
var patch = GetPatchInfo(repo, commit);
if (patch != null)
{
commitDto.LinesAdded = patch.LinesAdded;
commitDto.LinesDeleted = patch.LinesDeleted;
}
Console.WriteLine(commitDto.ToString());
list.Add(commitDto);
}
}

To avoid runtime dependencies, the tool was published as a single‑file self‑contained executable using .NET Core 3.0 with the following commands:

# publish win‑x64
dotnet publish -c Release -o publish/win‑x64 -r win‑x64 /p:PublishSingleFile=true /p:IncludeSymbolsInSingleFile=true /p:PublishTrimmed=true
# publish linux‑x64
dotnet publish -c Release -o publish/linux‑x64 -r linux‑x64 /p:PublishSingleFile=true /p:IncludeSymbolsInSingleFile=true /p:PublishTrimmed=true

A GitHub Actions workflow (YAML) was added so that each push automatically builds the binaries on high‑performance GitHub runners.

For reporting, the generated CSV files were imported into Microsoft PowerBI Desktop. Several dashboards were created to show total commits over time, lines added/deleted, contributor distribution by email domain, and temporal patterns (weekday vs. hour). Screenshots illustrate that the ASP.NET Core repository has commit history dating back to 2013, with peak activity in 2017‑2018 corresponding to major version releases.

The combined use of libgit2sharp, .NET Core publishing, and PowerBI satisfied the product manager’s requirements, and the open‑source project (https://github.com/leansoftX/dotnet-gitstats) invites further contributions.

backendCLIdata analysisgit.NET Corelibgit2sharpPowerBI
DevOps
Written by

DevOps

Share premium content and events on trends, applications, and practices in development efficiency, AI and related technologies. The IDCF International DevOps Coach Federation trains end‑to‑end development‑efficiency talent, linking high‑performance organizations and individuals to achieve excellence.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.