
Trace a Change with Line History Explainer
Explain who changed a line, when and why from read-only git history: blame grouped by commit, the history of a line range, text search across commits, rename follow and lines per author. It stops when a file is not tracked by git. Standard library only. Requires Python 3.9+ and git. It never commits, checks out, resets or pushes. #Ingegneria
What you get
- check: is the file tracked? It stops early for untracked, ignored, missing and staged-only files, so you never read a history that is not there
- blame: the commit, date, author and summary behind each group of lines in a range
- trace: every commit that changed a line range, oldest first
- search: the commits that added or removed a text or a regular expression, each labelled added, removed or changed
- follow: the history of a file across renames, with the old and new path
- who: how many lines each author owns now, for the whole file or a range
- report: check, blame, trace and who in one page, as text, Markdown or JSON
The problem
Before you edit a line you did not write, you want to know why it is that way. git blame shows the last commit, which is often a rename or a reformat. git log on a path goes silent at a rename. A file that is not tracked has no history at all, and a ledger or a file name will not tell you who owns it. This tool asks git the right question, groups the answer, and says plainly when there is no answer.
Requirements
A single-file Python tool (3.9+, standard library only; tested with Python 3.9.6 and 3.10.4 on macOS with git 2.16.3 and 2.50.1). Only these git commands are run: blame, log, ls-files, check-ignore, rev-parse, show. Nothing is committed, checked out, reset or pushed, and nothing is sent over a network.
Limits (read these)
- Git records who committed a change, not who decided it. A summary like "fix" explains nothing.
- blame reads the working tree by default, so an edited line is shown as Not committed yet. Pass --rev HEAD to read the last commit only.
- trace uses git log -L. It lists commits, not renames, so use follow to see the renames.
- search counts occurrences on added and removed lines. A commit that adds and removes the same number of matches is labelled changed.
- Without --follow, search sees only the commits made under the current path.
- With --regex, search reads every commit of the file with Python, so it is slower on long histories.
- In a shallow clone the history ends at the first commit that was fetched.

