Skip to content

How to Use Git History as a Codebase Analysis Tool

Use Git history analysis to find frequently changed files, co-change patterns and contributor concentration. Run reproducible queries and inspect their limits.

7 min read
Successive circuit board versions arranged in a stepped archive cabinet.
On this page

Your git history is the most underutilized dataset in your engineering organization. Every commit is a record of what changed, who changed it, when, and (if your commit messages aren't garbage) why. That's years of data about how your codebase evolves, sitting right there in your .git directory.

Most teams use git for exactly two things: committing code and resolving merge conflicts. That's like buying a Formula 1 car to drive to the grocery store.

I've been mining git history for insights since 2016, and I consistently find patterns that no other tool surfaces. Here's how you can do the same.

The Basics: What Git Log Actually Contains

From repository history to observations The diagram describes the data path, without claiming causal relationships. Commits Tree and parents Author, dates, message Compare revisions Changed paths Added/deleted lines Investigate patterns Hotspots and co-change Contributor concentration
Figure 1. Define how revisions are compared before interpreting the resulting measures.

Every git commit stores:[1]

  • Author and timestamp: Who made the change and when
  • Tree snapshot: The recorded file tree; Git computes changes by comparing revisions
  • Message: The developer's stated intent
  • Parent commits: The change's relationship to the project timeline

From these four pieces of data, you can derive:

  • Change frequency per file, per module, per author
  • Temporal coupling between files (which files change together)
  • Knowledge distribution (who knows what parts of the codebase)
  • Development patterns (when does the team work, how big are typical changes)
  • Risk indicators (which changes tend to precede bugs)

Use these commands alongside the code intelligence guide to connect repository history with the current structure of the application.

Finding Your Hotspots

Files that change frequently are candidates for investigation. Combine change frequency with code health, size and defect evidence before deciding which areas need review or refactoring.[2]

bash
# Files with the most commits in the last 6 months
git log --since="6 months ago" --pretty=format: --name-only | \
  grep -v '^$' | sort | uniq -c | sort -rn | head -25

When I run this on a typical project, the results always surprise the team. Files they thought were stable turn out to be constantly changing. Files they worried about turn out to be untouched.

Pair raw commit count with size and inspect the code hotspots before choosing a refactoring target:

bash
# For each hotspot, show its line count alongside commit count
git log --since="6 months ago" --pretty=format: --name-only | \
  grep -v '^$' | sort | uniq -c | sort -rn | head -25 | \
  while read count file; do
    if [ -f "$file" ]; then
      lines=$(wc -l < "$file")
      echo "$count commits | $lines lines | $file"
    fi
  done

A 50-line config file with 30 commits is a different story than a 2,000-line module with 30 commits.

Discovering Temporal Coupling

Repeated co-change can reveal a hidden dependency. Inspect the commits to distinguish a coordinated implementation change from broad refactors, formatting changes and other work that can touch unrelated files.[3]

bash
# Find files that frequently change in the same commit
python3 - <<'PY'
from collections import Counter
from itertools import combinations
import subprocess

revisions = subprocess.check_output([
    "git", "rev-list", "--no-merges", "--since=6 months ago", "HEAD"
], text=True).splitlines()
pairs = Counter()
for revision in revisions:
    paths = subprocess.check_output([
        "git", "diff-tree", "--root", "--no-commit-id", "--name-only",
        "-r", "-z", revision
    ]).split(b"\0")
    paths = sorted({path.decode("utf-8", "surrogateescape") for path in paths if path})
    pairs.update(combinations(paths, 2))
for (left, right), count in pairs.most_common(20):
    print(count, repr(left), repr(right))
PY

This command shows you file pairs that change together most often. Some of these will be expected (a component and its test file). But you'll also find surprising couples: a UI component and an unrelated API handler. A database migration and a seemingly unrelated utility function.

These unexpected couplings are architectural smells. They mean a change in one area requires a change in another, and that relationship isn't captured in the code's import graph. It's implicit knowledge that lives in developers' heads, and when those developers leave, the coupling causes bugs.

Mapping Knowledge Distribution

Inspect recorded contribution for important files, then ask the team who understands them. Git log and blame expose author history that can guide that discussion.[4]

bash
# Top contributor for each of your most-changed files
for file in $(git log --since="12 months ago" --pretty=format: --name-only | \
  grep -v '^$' | sort | uniq -c | sort -rn | head -20 | awk '{print $2}'); do
  echo "=== $file ==="
  git log --since="12 months ago" --pretty=format:'%an' -- "$file" | \
    sort | uniq -c | sort -rn | head -3
done

When one name dominates a critical file, investigate whether knowledge is concentrated there. Commit authorship alone does not establish a bus factor of 1. I have seen concentrated knowledge damage teams. Senior developer leaves, and suddenly nobody can confidently modify the payment processing module.

Spread knowledge through paired changes, architecture walkthroughs and rotating review responsibilities. Use the code ownership guide to make those responsibilities explicit.

Analyzing Commit Patterns

Commit patterns reveal how your team actually works, as opposed to how you think they work.

bash
# Commits by day of week
git log --since="6 months ago" --format='%ad' --date=format:'%A' | \
  sort | uniq -c | sort -rn

# Commits by hour
git log --since="6 months ago" --format='%ad' --date=format:'%H' | \
  sort | uniq -c | sort -rn

# Average commit size (lines changed)
python3 - <<'PY'
import subprocess

revisions = subprocess.check_output([
    "git", "rev-list", "--no-merges", "--since=3 months ago", "HEAD"
], text=True).splitlines()
changed_lines = 0
for revision in revisions:
    report = subprocess.check_output([
        "git", "show", "--format=", "--numstat", revision
    ], text=True)
    for line in report.splitlines():
        fields = line.split("\t", 2)
        if len(fields) == 3 and fields[0].isdigit() and fields[1].isdigit():
            changed_lines += int(fields[0]) + int(fields[1])
average = changed_lines / len(revisions) if revisions else 0
print(f"{average:.1f} textual lines per non-merge commit across {len(revisions)} commits")
PY

I use the commit-size analysis as a health check. Teams with an average commit size over 200 lines are likely batching too many changes together. Teams with an average under 20 lines might be committing too granularly (or their CI is so slow they split work to avoid long queues).

The Framework: MINE Your Git History

MINE Git history Map hotspots Find frequently changed files Identify coupling Inspect co-change patterns Name experts Review contribution concentration Examine trends Repeat comparable measurements
Figure 2. Keep query scope and interpretation consistent when repeating the analysis.

M - Map hotspots: Run the frequency analysis. Identify your top 20 most-changed files. This is your focus area.

I - Identify coupling: Run temporal coupling analysis. Find the unexpected file pairs. Document the hidden dependencies.

N - Name the experts: Map knowledge distribution. Identify bus factor risks. Start knowledge-spreading initiatives for critical areas.

E - Examine trends: Don't just look at a snapshot. Run these analyses monthly and track the trends. Is your bus factor improving or getting worse? Are your hotspots stabilizing or growing?

The Contrarian Take: Commit Messages Are Overrated for This

Most guides on git analysis emphasize the importance of good commit messages. And yes, good commit messages help humans understand changes. But for analytical purposes, the diff is far more valuable than the message.

I've mined insights from codebases with terrible commit messages ("fix," "wip," "stuff") because the structural data (what changed, who changed it, when, and what else changed at the same time) is all in the metadata, not the message.

Don't wait for your team to adopt conventional commits before you start analyzing your git history. The data you need is already there.

Automating the Analysis

Running git commands manually is fine for exploration, but you want automation for ongoing tracking. Here's what I recommend:

  1. Write a script that runs your key analyses (hotspots, coupling, knowledge distribution) weekly
  2. Output the results to a JSON file
  3. Store the JSON in a simple dashboard (even a Google Sheet works)
  4. Review the trends monthly in your engineering retrospective

The total investment is about a day of scripting. The payoff is continuous visibility into how your codebase is actually evolving, not how you hope it's evolving.

Tools like CodeScene and gitlog-to-csv can accelerate this. But the git commands I've shared above will get you 80% of the way there for zero cost.

Start mining. Your git history has been collecting data for years. It's time to use it.

Frequently asked questions

Does Git store each commit as a diff?

A commit records a tree snapshot, metadata and parent references. Git derives a diff by comparing revisions. This distinction matters when choosing how to analyse merges, root commits and file changes.

Does changing together prove two files depend on each other?

Repeated co-change is a useful investigation signal. A large mechanical refactor or a broad commit can also change unrelated files together, so inspect representative commits before treating the pattern as a dependency.

Does a single recorded author mean only one person knows a file?

Authorship can reveal concentrated contribution, but it does not record everyone who reviewed, paired on or learned the code. Discuss important single-author areas with the team before assigning knowledge risk.

What should I record to compare analysis over time?

Keep the time window, branch scope, merge handling and file filters alongside the results. Use the same definitions when repeating the analysis, and inspect changes in those definitions before interpreting a trend.

Sources

  1. [1]Git - Git Objects · Pro Git
  2. [2]Technical Debt — CodeScene 1 Documentation · CodeScene
  3. [3]Git - git-log Documentation · Git
  4. [4]Git - git-blame Documentation · Git

Checked against these sources on

Related Articles