Thursday, 27 December 2018

GIT: Using the Git blame command

19.1. Analyzing line changes with git blame

Using the Git log command and filtering the history is a useful tool for inspecting the project history. However, if you look at a particular file and find a bug in a particular line of code you would like to instantly know who was the last person who changed this line of code. Additionally, you would like to know why the developer did that i.e. locate the commit in which the change was done.
In Git, this feature is called git blame or git annotate. The git blame command allows you to see which commit and author modified a file on a per line base. That is very useful to identify the person or the commit which introduced a change.

19.2. Example: git blame

The following code snippet demonstrates the usage of the git blame command.
# git blame shows the author and commit per
# line of a file
git blame [filename]

# the -L option allows limiting the selection
# for example by line number

# only show line 1 and 2 in git blame
git blame -L 1,2 [filename]
The git blame command can also ignore whitespace changes with the -w parameter.

0 comments:

Post a Comment