Git Blame

Git, a version control software, is primarily used for source code management and tracking any changes any set of files. Git is very effective in coordinating the work of multiple people working on a project. Being a distributed revision control system, Git aims at speed, data integrity and support for distributed, non-linear workflows.

More than 1 developers may change the contents of a file. Using git blame, we can find the person responsible for the last change of code of each line. The command, as the name suggests, helps to find the person who changed a line of code and to blame them. In short, git blame shows the revision and author of each code of line of a file.

To get started with git blame, try the following syntax.

git blame filename
We then get the list of authors of each line of code for the file. git blame operates on individual files, therefore, it’s better to specify the path of the file. Here is a sample output of git blame.
$ git blame README.md
82496ea3 (kev 2018-02-28 13:37:02 -0800 1) # Git Blame example
82496ea3 (kev 2018-02-28 13:37:02 -0800 2)
89feb84d (Alie So 2018-03-01 00:54:03 +0000 3) new line
82496ea3 (kev 2018-02-28 13:37:02 -0800 4)
82496ea3 (kev 2018-02-28 13:37:02 -0800 5) git blame
82496ea3 (kev 2018-02-28 13:37:02 -0800 6)
89feb84d (Alie So 2018-03-01 00:54:03 +0000 7) sun is going down

Commonly used options

We can use a set of options for git blame. Some of them are given below.
git blame -L 1,5 README.md
This option restricts the display from lines 1 to 5.  
git blame -e README.md
This option displays the email address of the author instead of his username.  
git blame -w README.md
This option ignores the whitespaces in the file and mentions the authors of other lines.  
git blame -M README.md
This option detects the copied or moved lines within a file. The command returns the original author instead of the person who copied or moved the file.  
git blame -C README.md
This option detects the copied or moved lines among any files. The command returns the original author instead of the person who copied or moved the file.   git blame is a very useful command in finding the author of each line of code. and to see when the modifications were done. git blame comes in handy while managing a project.]]>