Git commands

git blame

git blame: display line-by-line commit history for a file.

The git blame command shows which commit last modified each line of a file, along with the author, timestamp, and line number. It is a quick way to understand why a line looks the way it does, who touched it last, or when a regression might have been introduced. Instead of searching through every commit manually, you can jump straight to the responsible change.

The output is read top to bottom like the file itself. Each line begins with an abbreviated commit hash, followed by author info, date, original line number, and then the line content from the file. You can point git blame at a file in your working tree or at a specific commit (for example, HEAD~3) to inspect an older version.

Result:
1b2c3d4 (Jane Doe 2024-02-19  12) import React from "react";
5e6f7a8 (Jane Doe 2024-02-20  13) import {Button} from "./Button";
5e6f7a8 (Jane Doe 2024-02-20  14)
9a0b1c2 (Alex Roe 2024-03-01  15) export function Header() \{
9a0b1c2 (Alex Roe 2024-03-01  16)   return <Button>Buy tickets</Button>;
9a0b1c2 (Alex Roe 2024-03-01  17) }

Use cases

  1. Pinpoint ownership of a line so you can open the exact commit, read its message, and understand the intent before changing or reverting code.
  2. Collect quick context on unfamiliar files, including the author, timestamp, and original line number, which makes it easier to ask focused follow-up questions or split work with teammates.
  3. Track regressions or attribute work by pairing the blamed commit with git show to see when a bug landed—or to copy the attribution details into reviews, changelogs, or docs.

Examples

Show who last modified each line of a file in the current working tree:

git blame src/components/Header.tsx

Limit the output to a specific range of lines using the -L option (start and end are inclusive):

git blame -L 25,40 src/components/Header.tsx

Blame the version of the file that existed two commits ago:

git blame HEAD~2 -- src/components/Header.tsx

The -- separator is optional but prevents Git from mistaking the file path for a revision name.

Include the author's email in the output for easier follow-up:

git blame --show-email src/components/Header.tsx
© 2024-2025 GitByBit.All rights reserved.