Skip to content

annotate Git Command Guide

The git annotate command (an alias for git blame) annotates each line in a file with the commit information that most recently modified it. This is useful for determining when and by whom changes were made, aiding in code reviews and debugging. It shows commit IDs, authors, timestamps, and the actual lines.

Terminal window
git annotate [options] [rev-opts] [rev] [--] <file>
OptionDescription
-bDo not show object names for boundary commits
-lAnnotate only the first line of each commit
-tShow raw timestamp instead of relative time
-SUse revs from the specified file for blame
—show-statsInclude additional statistics
-pShow additional info for each line
-eShow email instead of author name
—since=Show changes more recent than date
-L <start,end>Annotate only lines from start to end
-CDetect moved or copied lines within the same file
-MDetect moved or copied lines across files
ParameterDescription
revCommit to examine
fileFile to annotate
Terminal window
git annotate file.txt

Shows the last commit that modified each line in file.txt.

Terminal window
git annotate --email file.txt

Displays author emails instead of names.

Terminal window
git annotate -L 10,20 file.txt

Annotates only lines 10 through 20.

Terminal window
git annotate -t file.txt

Displays absolute timestamps instead of relative ones.

Terminal window
git annotate -M file.txt

Attempts to find lines that were moved or copied from other files.

How do I use git annotate to find who changed a specific line?

Section titled “How do I use git annotate to find who changed a specific line?”

To find the author and commit for a specific line, use:

Terminal window
git annotate -L <line-number>,<line-number> <file>

How can I see the email addresses instead of names in git annotate?

Section titled “How can I see the email addresses instead of names in git annotate?”

To display email addresses for authors in git annotate, execute:

Terminal window
git annotate -e <file>

How do I limit git annotate to a specific range of lines?

Section titled “How do I limit git annotate to a specific range of lines?”

To limit the annotation to a specific range of lines, use the following syntax:

Terminal window
git annotate -L <start-line>,<end-line> <file>

How can I get raw timestamps with git annotate?

Section titled “How can I get raw timestamps with git annotate?”

To get raw timestamps instead of relative times, use:

Terminal window
git annotate -t <file>

How do I detect copied or moved lines using git annotate?

Section titled “How do I detect copied or moved lines using git annotate?”

To detect copied or moved lines within the same file, use:

Terminal window
git annotate -C <file>

How can I show additional statistics with git annotate?

Section titled “How can I show additional statistics with git annotate?”

To include statistics about the annotated file, use:

Terminal window
git annotate --show-stats <file>
  1. Viewing authorship information per line in a file
  2. Finding changes made within a specific time frame
  3. Displaying author email addresses instead of names
  4. Annotating only a specific range of lines in a file
  5. Detecting moved or copied lines within the same file
  6. Detecting moved or copied lines across different files
  7. Showing raw timestamps for each line change