---
title: "How do I see the history of a single file in Git?"
description: "Use git log --follow -p to see every commit that touched a file, including renames, and git blame to see who last changed each line and why."
url: https://www.danny.engineering/answer/git/how-do-i-see-the-history-of-a-single-file-in-git
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T20:31:00.000Z
tags: ["Git"]
---

# How do I see the history of a single file in Git?

## The short answer


Pass the file path to `git log`. Add `--follow` so the history continues past renames, and `-p` to see the actual change in each commit. To see who last changed each line, use `git blame`.


```bash
git log --follow -p -- src/utils/format.ts
git blame src/utils/format.ts
```


## Why it happens


Git does not store a history per file. It stores snapshots of the whole project, one per commit. When you ask for a file's history, Git walks the commits and keeps only the ones where that path changed.


That is why renames trip people up. If `format.js` became `format.ts` three months ago, a plain `git log -- format.ts` stops at the rename, because before that commit no file had that path. `--follow` tells Git to detect the rename and keep following the old name. It only works with a single file, not a directory.


The `--` separator tells Git that what follows is a path, not a branch name. You can usually leave it out, but it avoids confusion when a file and a branch share a name.


## How to fix it


### List the commits that touched a file


Start with a compact list, then dig into the commits that look interesting.


```bash
# One line per commit
git log --oneline --follow -- src/utils/format.ts

# Add the diff for each commit
git log --follow -p -- src/utils/format.ts

# Just the size of each change
git log --follow --stat -- src/utils/format.ts
```


To see the file exactly as it was in an older commit, use `git show` with the commit and the path.


```bash
git show a1b2c3d:src/utils/format.ts
```


### Find who changed each line with git blame


`git blame` prints every line with the commit, author and date of its last change. It answers "why is this line here?" quickly, because you can take the commit hash and run `git show` on it to read the full message.


```bash
# Only lines 40 to 60
git blame -L 40,60 src/utils/format.ts

# Ignore whitespace changes and follow lines moved or copied from other files
git blame -w -C src/utils/format.ts
```


If a big formatting commit hides the real history, list its hash in a file and tell blame to skip it.


```bash
echo "a1b2c3d4e5f6..." >> .git-blame-ignore-revs
git config blame.ignoreRevsFile .git-blame-ignore-revs
```


GitHub and GitLab also read a `.git-blame-ignore-revs` file in the repository root for their blame views.


### Follow a single function over time


`git log -L` tracks a range of lines, or a function by name, through history. It shows each commit that changed that part of the file along with the diff.


```bash
# By line range
git log -L 40,60:src/utils/format.ts

# By function name
git log -L :formatPrice:src/utils/format.ts
```


The function form relies on Git recognising function boundaries for that language, which works well for most C-like languages, including JavaScript and TypeScript.


### Search for when some code appeared or vanished


If you know a piece of text but not where it lived, the "pickaxe" options search the diffs themselves.


```bash
# Commits that changed the number of times this string appears
git log -S "legacyFormat" --oneline

# Commits whose diff matches a regular expression
git log -G "format(Price|Date)" --oneline
```


## Common pitfalls

- **Forgetting** **`--follow`****.** Without it, history stops at the last rename and older commits look missing.
- **Using** **`--follow`** **on a folder.** It only works for one file. For a directory, use `git log -- src/utils/` without it.
- **Blaming the formatter.** A mass reformat makes `git blame` point at one commit for every line. Use `-w` or an ignore-revs file.
- **Reading blame as fault.** Blame shows the last change, not who wrote the original logic. Check earlier commits with `git log -L` before drawing conclusions.
- **Looking at the wrong branch.** `git log` shows history reachable from your current branch. Add a branch name, or `--all`, to look elsewhere.

## Related reading

- [git-scm.com: git log](https://git-scm.com/docs/git-log)
- [git-scm.com: git blame](https://git-scm.com/docs/git-blame)
