Read Anthropic’s case study about Graphite Reviewer

How to use the `git blame` command

Greg Foster
Greg Foster
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


git blame is used to examine the history of a file, showing line-by-line revisions alongside the name of the last person who modified each line, the commit hash, and the timestamp of the change. This functionality is useful for developers seeking more context on why certain changes were made, and for identifying who made specific changes for further discussion.

To use git blame, execute the git blame command followed by the filename of the file you wish to examine:

Terminal
git blame README.md

This will display the README.md file's content in the terminal, with each line prefixed by the commit hash, author, date, and the line number.

For example you might see something like this:

Terminal
a1b2c3d4 (Jane Doe 2022-01-15 12:34:56 +0000 1) # Project Title
e5f6g7h8 (Alex Smith 2022-02-20 14:30:22 +0000 2) A brief description of the project.
a9b8c7d6 (Alex Smith 2022-03-10 16:45:33 +0000 3)
d5e6f7g8 (Jane Doe 2022-04-05 18:50:44 +0000 4) ## Features
g1h2i3j4 (Jane Doe 2022-05-25 20:55:55 +0000 5) - Feature 1
k5l6m7n8 (Charlie Brown 2022-06-15 23:00:00 +0000 6) - Feature 2
b3c4d5e6 (Jane Doe 2022-07-05 08:05:06 +0000 7)
f7g8h9i0 (Alex Smith 2022-08-10 10:10:10 +0000 8) ## Installation
j1k2l3m4 (Alex Smith 2022-09-20 12:15:20 +0000 9) Instructions on how to install the project.
e5f6g7h8 (Jane Doe 2022-10-30 14:20:30 +0000 10)
a1b2c3d4 (Charlie Brown 2022-11-25 16:25:40 +0000 11) ## Contributing
d5e6f7g8 (Charlie Brown 2022-12-15 18:30:50 +0000 12) Guidelines for contributing to the project.

In this output:

  • Each line of the README.md file is shown.
  • The commit hash (e.g., a1b2c3d4) of the last commit that modified the line is displayed first.
  • This is followed by the name of the author who made the commit (e.g., Jane Doe), and the date and time of the commit (e.g., 2022-01-15 12:34:56 +0000).
  • The line number within the file is then shown in parentheses (e.g., 1)).
  • Finally, the content of the line itself is displayed (e.g., # Project Title).
  • Specific Line or Range: To focus on a specific line or a range of lines, use the -L option:

    Terminal
    git blame -L 50,60 README.md

    This command will show details for lines 50 to 60 of the README.md file.

  • Show Commit Message: Adding the -s option shows the commit messages, helping to understand the context of changes:

    Terminal
    git blame -s README.md
  • Ignoring Whitespace: Use -w to ignore whitespace changes, focusing on substantive changes to the file:

    Terminal
    git blame -w README.md
  • GUI Tools: Many graphical Git tools, and IDEs, such as the JetBrains suite, VS Code, or the Graphite web app, offer a blame feature that visualizes git blame information in a more user-friendly manner.
  • Investigating Changes: Use git blame in conjunction with git log and git diff for a comprehensive view of a file's history and changes over time.
  • Dealing with Renames: If a file was renamed, use the --follow option to track its history across the rename.

For more information see the official documentation on Git blame.

0 min read
Share
Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2