Git Blame

Last Updated : 6 May, 2026

Git blame is a Git command that annotates each line in a file with the following information.

  • The last commit that modified the line.
  • The author of the commit.
  • The timestamp of the change.
  • The line number and code content (optionally).

Syntax

git blame [options] <file-name>

Step-by-Step Guide to use git-blame

To identify the author and commit details for a specific line in a file within a Git repository, use the appropriate Git command as shown below.

Step 1: Move to an empty folder and initialise it with an empty git repository.

Step 2: Clone the required repository from GitHub and navigate to the cloned directory.

cloning create-react-app repository from GitHub

Step 3: Run the git blame command with the relative file path to view the author and commit details for each line.

git blame <file-name>

Step 4: To view details for CONTRIBUTING.md in the current directory, run the following command:

git blame CONTRIBUTING.md

Output:

The output of the git blame command on the CONTRIBUTING.md file

Tip: Observe that the last column of output displays the line number along with the code on that line.

Output study

Let's examine the first line of output:

Commit IdAuthor NameTimestampCode
46cf3fc43Dan Abramov2016-09-02 14:29:08 +0100# Contributing to Create React App
  • Commit ID: Identifies the commit where the line was last modified.
  • Author Name: Shows who last changed the line (email can be retrieved if needed).
  • Timestamp: Displays when the commit was made (raw format available with -t).
git blame -t CONTRIBUTING.md

Output:

raw timestamp using -t option with the git blame command

Viewing the commit details

To view detailed information about a specific commit, use the commit ID obtained from the git blame output.

Steps:

  1. Copy the commit ID from the git blame result.
    (Example: 46cf3fc43 from CONTRIBUTING.md)
  2. Run the following command:
git log -p <commit-id>

Example:

git log -p 46cf3fc43
  • git log displays commit history.
  • -p / --patch shows author details and code changes (additions and deletions).

Options with git blame

Git provides multiple options to analyze file modifications in detail.

To view output for a range of lines

git blame -L start-line,end-line <file-name>

The below command shows output for lines 2 to 5 both inclusive.

git blame -L 2,5 CONTRIBUTING.md

The output is shown below:

The output of the git blame command for a given range of lines

Note: You will get the same output for command - git blame -L 4,+3 README.md. Here 4,+3 signifies output for 3 lines starting from the fourth line.

To view the author email id

git blame -e CONTRIBUTING.md

The above command will show the author's email id instead of the author's name in the result. The output is shown below:

To view changes not older than the given time

git blame --since=3.months CONTRIBUTING.md
  • Commits starting with ^ indicate changes made before the specified time.
  • In this case, they represent commits older than three months.
  • These older commits appear in the git blame output.
  • Filter them out to focus only on recent changes.

Output:

The output of the git blame command with commits not older than three months (without removing unrequired commits)
git blame --since=3.months CONTRIBUTING.md | grep -v '^\^'
  • Use git blame --since=3.months CONTRIBUTING.md to mark commits older than three months.
  • Commits prefixed with ^ indicate changes made before the specified time.
  • Filter out these older commits to focus on recent changes:
The output of the git blame command with commits not older than three months (after removing unrequired commits)

An alternate option to the command line (GUI based)

Git hosting sites like GitHub, Bitbucket, GitLab offer GUI displays for git blame, which gives a clear display of modification history in a file.

Example: GitHub

Step 1: Navigate to the file for which you want to see the modification history and click on the Blame option as shown below.

Step 2: The structure of output is described in the image below :

labeled picture of blame option on GitHub

git blame is a powerful command for analyzing line-level commit history and works effectively with other Git commands for deeper repository inspection.

Comment

Explore