git-loc
Generate a per-language lines of code time series for a Git repository without checking out each commit.
This tool walks the linear history of a branch/ref, computes a tree diff at each commit, and updates running totals using git blob contents + tokei for language detection and counting.
- Uses tokei for language detection and for
code / comments / blankscounts (including embedded-language blobs). - Avoids expensive checkouts: reads blobs directly from the Git object database.
- Caches per-blob tokei results in-memory, so identical blobs are only counted once per run.
- Optional SVG plot of the top languages over time.
Note: “lines of code” usually refers to the
codecolumn (non-blank, non-comment lines). The CSV also includescomments,blanks, andlines = code+comments+blanks.
Install
From crates.io
From source
Usage
Emit CSV (stdout)
Emit CSV + SVG plot
Plot options
# Use code/comments/blanks/lines for the plot metric
# Plot top 5 languages
# Show git tags on the plot
# Only include selected languages (repeatable or comma-separated)
Only count a subdirectory
Disable the progress bar
Output format
The CSV is long-form: one row per (commit, language).
Columns:
commit: commit SHAtimestamp: commit time (unix seconds)datetime: commit timelanguage: language name (as reported by tokei)code: code linescomments: comment linesblanks: blank lineslines:code + comments + blanks
This long format is convenient for plotting.
Plot
--plot <path.svg> writes an SVG chart of the top languages ranked by totals at the final commit.
Plot-related flags:
--plot-metric code|lines|comments|blanks(default:code)--plot-top N(default:8)--plot-tagsshows git tags on the plot--only <LANG>repeatable or comma-separated--no-progressdisables the progress bar on stderr
How it works
- Resolve
--rev(defaultHEAD). - Build the first-parent chain from root → tip.
- For each commit:
- Diff
parent_tree → commit_tree - For each changed file:
- If the old blob exists: subtract its cached per-language tokei counts
- If the new blob exists: add its cached per-language tokei counts
- Diff
- Emit the current per-language totals (and optionally add a plot point).
Counting is done by writing blob bytes to a temporary file (with the original basename so tokei’s path-based detection works), then calling tokei as a library.