In Git, git blame is a command that can be used to view the author and last modification time of each line in a file. This is useful for identifying who made changes to a file and when those changes were made.
Here’s how to use git blame:
Open your Git repository in your terminal.
Use the git blame command followed by the path to the file that you want to view:
# View the git blame information for a file
git blame <file-path>
The output of the git blame command will display the commit hash, author name, and last modification time for each line in the file. For example:
abc1234 (John Smith 2022-03-18 13:00:00 +0800 1) This is the first line of the file
def5678 (Jane Doe 2022-03-19 14:00:00 +0800 2) This is the second line of the file
abc1234 (John Smith 2022-03-18 13:00:00 +0800 3) This is the third line of the file
In this example, the first and third lines of the file were last modified by John Smith on March 18, 2022, and the second line was last modified by Jane Doe on March 19, 2022.
Use the -L option followed by a range of line numbers to view the git blame information for a specific range of lines in the file. For example:
# View the git blame information for lines 3-5 of a file
git blame -L 3,5 <file-path>
In this command, -L 3,5 specifies that you want to view the git blame information for lines 3-5 of the file.
In summary, git blame is a command that can be used to view the author and last modification time of each line in a file. This is useful for identifying who made changes to a file and when those changes were made. You can use git blame followed by the path to the file to view the git blame information for the entire file, or you can use the -L option followed by a range of line numbers to view the git blame information for a specific range of lines in the file.