What is Git Blame?

Git Blame is a tracking command used in Git to find the Author Name and commit information of the last modified version of the source file.

You can see information related to each line of the file by using this command.

Syntax

The syntax for the simple Git blame command is:

$ git blame YourFileName

The syntax will give information for each line in the following sequence:

Commit Hash(short) Author Name Date Time
//Example
7009f2ae (Alice 2021-03-01 03:45:03 +0301 3) <head> 

Blaming Range of Code Lines

$ git blame YourFileName -L StartingLineNo,EndingLineNo
//$ git blame YourFileName -L 3,10  

OR

$ git blame -L StartingLineNo,EndingLineNo YourFileName 
//$ git blame -L 3,10 YourFileName

Displaying No of Lines AFTER a Specific Line

$ git blame -L StartingLineNo,+NoOfLines Along With StartingLine  YourFileName 
//$ git blame -L 3,+10 YourFileName  
//It will display lines from LineNo 3 till 12

Displaying No of Lines BEFORE a Specific Line

$ git blame -L StartingLineNo,-NoOfLines Along With StartingLine  YourFileName 
//$ git blame -L 30,-10 YourFileName  
//It will display lines from LineNo 21 till 30

Blaming By Timestamp

$ git blame YourFileName --since=5.days  
//Only Display changes made within Last 5 days
OR
$ git blame --since=2.weeks-- YourFileName 
//Not display changes older than 2 weeks

Ignoring Whitespace Changes

$ git blame -w YourFileName 

Display Author’s Email Instead Of Author’s Name

$ git blame YourFileName -e   OR   $ git blame -e YourFileName 

Detecting Moved/Copied Lines within File AND From Other Files

With this, you will see the original author instead of the one who copied the lines:

//Within same File
$ git blame -M YourFileName 
//From Other Files 
$ git blame -C YourFileName 

Long commit Hash

//It will Display LongCommit hashes instead of Default shortCommit hashes
$ git blame -l YourFileName 

Getting Help Related To GitBlame

$ man git-blame   OR   $ git help blame

Aliasing GitBlame

git config --global alias.YourAliasName blame
//Examples
git config --global alias.who blame  // Will change Git blame to Git who
OR 
git config --global alias.praise blame   
//will change Git blame to Git praise

Free Resources