Forrest logo
back to the git tool

git-annotate:tldr:a1f8a

git-annotate: Print a file with the author name and commit hash prepended to each line.
$ git annotate ${filename}
try on your machine

The git annotate command in Git is used to display the entire file's content alongside the revision history, showing which line of the file was last modified by which commit.

Here is how you would use the git annotate command:

git annotate ${filename}
  • ${filename} refers to the name of the file you want to assess, that is the file for which you want to see its revision history and line-by-line annotation.

When you run the command, Git will fetch the revision history of the specified file, and for each line, it displays the commit hash, author, and the date of the last modification. This information allows you to trace the changes made to every individual line in the file.

The output of the git annotate command will look something like this:

41a4dc8 (John Doe 2021-02-25 12:45:43 -0500 1) This is the initial text in the file.
41a4dc8 (John Doe 2021-02-25 12:45:43 -0500 2) It has multiple lines.
ea571d7 (Jane Smith 2021-02-27 09:18:12 -0500 3) Some changes made here.
ea571d7 (Jane Smith 2021-02-27 09:18:12 -0500 4) More changes on this line.
...

Each line is prefixed with the commit hash (e.g., 41a4dc8), followed by the author's name, the date and time of the modification, and finally, the content of the line itself.

Using git annotate, you can identify who made specific changes to a file and when, which can be useful for understanding the history and evolution of a file.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the git tool