git blame <pathname>

Annotate each line in `<pathname>` with the commit SHA, author, and timestamp of its last modification.

This command annotates each line of a file with the commit information and author who last modified it, providing a clear link between code and its history.

It operates by traversing the commit history of the repository to identify the most recent change for each line in the target file, then prints the commit SHA, author name, commit date, and line content; you can refine its output with flags like -L <start>,<end> to narrow the annotation to specific line ranges, -e to include author emails, -w to ignore whitespace when assigning blame, or --line-porcelain for a machine-readable format.

Variations and related commands include using git blame -L5,15 to focus on lines 5 through 15, git blame --line-porcelain for scripting purposes, or aliases like git annotate; complementary tools include git log -L for viewing diffs of specific line ranges, git log -S or -G (the pickaxe) for searching content changes, and commands like git log -p or git log --follow to trace file history and content evolution.

Related commands

Welcome to GitExamples!

Sign in to enable bookmarking, reminders, progress-tracking and more...