Using git blame

Last updated on
18 September 2020

Git's blame command helps you determine when a particular change was made. The unofficial git fame command helps you calculate change statistics. This page describes how to use both commands. For command-line versions, you will first need to clone the git repository, and (in a terminal window) change to the directory where your local clone is located.

Using git blame on the command line

In your terminal, run the command git blame <options> <filename>, where the filename is the name of the file you wish to run the blame on, and the options allow you to specify things like line number and range. See the git blame documentation for details. For example, this command will figure out when lines 62 through 76 of a particular file were changed:

git blame core/lib/Drupal/Core/Entity/Entity.php -L 62,76

In the results of your git blame, you should see a character string for the commit that made the last change to each line. Running git show <commit string> should give you more details of that specific commit. The commit message should also contain the Drupal.org issue ID number, which you can read for background information on the commit (go to drupal.org/node/ISSUE_ID to read the issue).

Using git blame in the GUI

If you click on the Browse code repository link from a project page, you will see a GitLab browser for the source code in that repository. For example, the GitLab source code browser for the Admin Toolbar project is at https://git.drupalcode.org/project/admin_toolbar.

Once you are in the source code browser for the project, follow the steps in the GitLab blame documentation to run the blame command.

Tags

Help improve this page

Page status: No known problems

You can: