Glossary · Git history

What is code churn?

In software development, code churn is the amount of code added, changed or deleted in a file, module or repository over a period of time. It is usually measured as lines added plus lines deleted, or as the number of commits, taken from version control. It says where work happens, not whether the work is good.

Last reviewed: November 2026

Also called Churn rate (software), Code volatility, Change frequency

In depth Code churn: what it is, how to measure it and what it predicts: git commands that run, the research behind churn, and why it fails as a productivity metric.

How code churn is measured

Churn has two common definitions. Line churn is lines added plus lines deleted. Commit churn is the number of commits that touched the file. Both come from git log, and both need a window (30, 90 or 180 days) to mean anything.

A worked example for api/orders.py over 90 days:

CommitLines addedLines deletedChurn
a1401050
b25510
c312080200

Line churn is 260 and commit churn is 3. If the file is 400 lines long today, relative churn is 260 / 400 = 0.65. A modified line counts as one deletion plus one addition, so editing 10 lines is 20 churn. Merge commits are usually excluded so the same change is not counted twice.

Why code churn matters

Churn points at the files where change keeps landing. Repeated change means repeated review, repeated testing and more chances to break something. The research favours the relative version: Nagappan and Ball, "Use of Relative Code Churn Measures to Predict System Defect Density" (ICSE 2005), studied Windows Server 2003 and reported that relative churn measures predicted defect density well while absolute churn did not.

Churn is a weak measure of developer productivity. Formatting, renames, generated files and refactors all raise it without adding features. Read it as a map of activity, then combine it with cyclomatic complexity to find a code hotspot.

How to measure code churn yourself

Git alone is enough:

# Added and deleted lines per file over 90 days, summed and ranked by total churn
git log --since="90 days ago" --no-merges --numstat --pretty=format: \
  | awk 'NF==3 {c[$3]+=$1+$2} END {for (f in c) print c[f], f}' \
  | sort -rn | head -20

Binary files print - instead of numbers and add nothing to the sum. Renames print as old => new and can split a file's history, so check moved files by hand. Exclude lockfiles and generated code with pathspecs. For commit counts only, git log --name-only --pretty=format: piped through sort | uniq -c is enough. The linked guide covers these edge cases in detail.

How repowise measures code churn

repowise reads git log --numstat per file when it indexes (the last 5,000 commits by default) and stores, per file:

  • Commits in the last 30 and 90 days, lines added and deleted in the last 90 days, and the average lines changed per commit.
  • A recency-weighted churn score: each commit contributes its lines changed divided by 100, capped at 3, and its weight halves every 180 days. Last week's commit counts far more than one from a year ago.
  • A churn percentile: the file's rank by that score among the repository's code files. Files in the top quartile that also clear minimum activity floors are flagged as hotspots (see code hotspot).

You see these on the Hotspots page of the dashboard, in get_context and get_risk over MCP, and with repowise risk --target <file>. They come from git only, with no model involved, so the same history gives the same numbers. See git intelligence.

FREQUENTLY ASKED

Code churn: questions

Is code churn the same as customer churn?

No. Customer churn is the rate at which paying users cancel. Code churn is how much a codebase changes over time. The two share a word and nothing else.

Is high code churn bad?

Not by itself. A new feature under active development has high churn by design. High churn is a warning when it sits on complex code, repeats on the same file after bug fixes, or follows a release.

How do you calculate code churn?

Sum lines added and lines deleted per file over a window, for example 90 days, using git log --numstat. To compare files of different sizes, divide by the file's current line count to get relative churn.

What is a good code churn rate?

There is no universal number. Compare files within the same repository and watch for outliers and trends: the top few percent of files by churn are usually where reviews, bugs and merge conflicts cluster.

See it on your own repository.

Index a repository free and read the result for your own code and history. Rolling it out to a team? We will walk you through it.