View a file’s change history in Git
Follow a file through commits and detected renames, inspect patches, and distinguish line attribution from a complete history.
Use git log --follow -- path/to/file to inspect one file's history across detected renames. Add -p for patches or --stat for summaries. The result depends on available commits and history traversal; it is not a guarantee that every earlier incarnation of a split or rewritten file will be found automatically.
Select the level of detail
git log --follow --oneline -- src/app.js
git log --follow -p -- src/app.js
git log --follow --stat -- src/app.js
git log --follow --since='3 months ago' -- src/app.js
The separator distinguishes paths from revisions. These commands start from the current history unless other revisions are supplied. Time filtering can hide older relevant changes, and a shallow clone may not contain them at all.
Rename following uses similarity detection and supports a single path. It can lose the trail through complex merges, splits, or substantial rewrites. When necessary, identify the old path and continue manually:
git log --all --full-history -- old/path.js
--all searches refs present locally, not every branch on every server or every unreachable object. Fetch the relevant history if it is missing.
Inspect line attribution
git blame -- src/app.js
git blame -L 50,80 -- src/app.js
Blame attributes the current lines to commits, using recorded author metadata. It does not show every change that ever affected the file, and deleted lines are not present in that view. A formatting change may dominate attribution; options such as -w or a reviewed ignore-revisions file can help investigate beyond formatting, with their own attribution tradeoffs.
Deleted files and snapshot comparisons
git log --all --diff-filter=D -- old/path.js
git show 'DELETION_COMMIT^:old/path.js'
git diff A B -- path/to/file.js
Replace the placeholder deletion commit with the correct ID. Its first parent must contain the file; choose the appropriate parent explicitly for a merge. A deleted file remains inspectable only while the necessary history and objects are available.
The diff compares the named path between two snapshots. If the path changed, inspect the rename and relevant historical names rather than assuming a current-name filter automatically finds every old path.
Editor and hosting views
GitLens in VS Code, JetBrains' file history, and GitHub's History and Blame views provide convenient navigation. Their filters and available repository data may differ from a local command, so check the selected branch, path, and comparison when results differ.
For a focused investigation, start with the compact log, open the relevant patch, and use blame only to locate the origin of a specific current line. Each view answers a different question.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan