The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Build a Git commit frequency chart

To build a Git commit frequency chart, you can follow these general steps depending on the tools or programming languages you prefer. Below is a practical approach using Python with Matplotlib to generate a chart from Git log data.

Step 1: Export Commit Data

Run the following command in your Git repository to extract commit timestamps:

bash
git log --pretty=format:'%ad' --date=short > commits.txt

This creates a commits.txt file with dates of each commit in YYYY-MM-DD format.


Step 2: Python Script to Create Frequency Chart

Here’s a complete Python script to read the commit dates, count them, and plot a frequency chart:

python
import matplotlib.pyplot as plt from collections import Counter from datetime import datetime import matplotlib.dates as mdates # Load commit dates with open('commits.txt', 'r') as file: dates = [line.strip() for line in file] # Count commits per date commit_counts = Counter(dates) # Sort by date sorted_dates = sorted(commit_counts.items(), key=lambda x: datetime.strptime(x[0], '%Y-%m-%d')) dates = [datetime.strptime(date, '%Y-%m-%d') for date, _ in sorted_dates] counts = [count for _, count in sorted_dates] # Plot plt.figure(figsize=(12, 6)) plt.plot(dates, counts, marker='o', linestyle='-') plt.title('Git Commit Frequency Over Time') plt.xlabel('Date') plt.ylabel('Number of Commits') plt.grid(True) # Format x-axis plt.gca().xaxis.set_major_locator(mdates.WeekdayLocator(interval=1)) plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d')) plt.xticks(rotation=45) plt.tight_layout() plt.show()

Optional Enhancements:

  • Group by week/month: Use pandas to resample the commit data by week/month.

  • Heatmaps: Use seaborn or similar to create calendar-style heatmaps.

  • CLI Tools: For simpler analysis, try gitstats or gitinspector.

Would you like the chart grouped weekly or monthly instead of daily?

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About