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.
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.
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 monthsgit 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 countgit 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.
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 commitpython3 - <<'PY'from collections import Counterfrom itertools import combinationsimport subprocessrevisions = 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.
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 filesfor 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 -3done
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.
Commit patterns reveal how your team actually works, as opposed to how you think they work.
bash
# Commits by day of weekgit log --since="6 months ago" --format='%ad' --date=format:'%A' | \ sort | uniq -c | sort -rn# Commits by hourgit log --since="6 months ago" --format='%ad' --date=format:'%H' | \ sort | uniq -c | sort -rn# Average commit size (lines changed)python3 - <<'PY'import subprocessrevisions = subprocess.check_output([ "git", "rev-list", "--no-merges", "--since=3 months ago", "HEAD"], text=True).splitlines()changed_lines = 0for 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 0print(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).
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.
Running git commands manually is fine for exploration, but you want automation for ongoing tracking. Here's what I recommend:
Write a script that runs your key analyses (hotspots, coupling, knowledge distribution) weekly
Output the results to a JSON file
Store the JSON in a simple dashboard (even a Google Sheet works)
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.
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.
Five predictions for where code intelligence is heading by 2028, based on 6 years of building tools in this space. Includes what's real, what's overhyped, and a maturity model for planning.
Most code quality dashboards fail because they track too many metrics and live outside the team's workflow. Here are exactly 7 metrics and a 3-week adoption plan that actually works.
Build software composition analysis into CI with dependency inventories, vulnerability checks and licence review. Define owners, response targets and follow-up.
Architecture fitness functions are automated tests for your system's structural properties. Here's how to implement the 5 most impactful ones and integrate them into your CI pipeline.
Your PR data reveals team bottlenecks invisible in standups. Here's how to measure TTFR, review distribution, and cycle time with the REVIEW framework.