With my colleagues, we use the Infrastructure as Code (IaC) methodology to manage most of our infrastructure. Even though we try to comment on every piece of code that is not self-descriptive, sometimes we need to contact the original author of a line (or block of lines). Of course, there is the git blame command that identifies the author of the last change on every line of a file. The command without any parameters shows the commit ID, author’s name, date of the last change, and content of the line. Let’s take a look at the file SECURITY.md from the FastAPI project:
$ git blame SECURITY.md
377234ad8 (Sebastián Ramírez 2021-06-07 14:55:40 +0200 1) # Security Policy
377234ad8 (Sebastián Ramírez 2021-06-07 14:55:40 +0200 2)
377234ad8 (Sebastián Ramírez 2021-06-07 14:55:40 +0200 3) Security is very important for FastAPI and its community. 🔒
377234ad8 (Sebastián Ramírez 2021-06-07 14:55:40 +0200 4)
377234ad8 (Sebastián Ramírez 2021-06-07 14:55:40 +0200 5) Learn more about it below. 👇
377234ad8 (Sebastián Ramírez 2021-06-07 14:55:40 +0200 6)
377234ad8 (Sebastián Ramírez 2021-06-07 14:55:40 +0200 7) ## Versions
Now you see the first seven lines. What if you want to get contact information for the author of the seventh line? You will use the parameter --show-email
to show the email instead of the author’s name, and -L <start>,<stop>
to print only a specific line (there is no --number
parameter, therefore you have to define a range of line numbers). Here is the command example and its output:
$ git blame --show-email -L 7,7 SECURITY.md
377234ad8 (<[email protected]> 2021-06-07 14:55:40 +0200 7) ## Versions
Tip: If you have to read through the entire blame output, I suggest using the --color-lines
parameter. This will change the color of lines whose meta information is different from the previous one. For example: