Git blame

The git blame command is used to examine the content of any file line by line. It helps you determine who made changes to a file and when those changes were made. This command is particularly useful for tracking down the origin of a specific change or understanding the history of a file.



Tutorials dojo strip

Initial Example

$ git blame <your_file_name>




BLAME Options

OptionDescription
-bShow blank SHA-1 for boundary commits. Controlled by blame.blankBoundary config option.
--rootDo not treat root commits as boundaries. Controlled by blame.showRoot config option.
--show-statsInclude additional statistics at the end of blame output.
-L <start>,<end> -L :<funcname>Annotate only the specified line range or function name regex. Can be specified multiple times.
-lShow long revision hashes.
-tShow raw timestamp.
-S <revs-file>Use revisions from the specified file instead of calling git-rev-list.
--reverse <rev>..<rev>Walk history forward instead of backward. Shows the last revision in which a line existed. Requires a range of revisions.
--first-parentFollow only the first parent commit upon seeing a merge commit.
-p, --porcelainShow in a format designed for machine consumption.
--line-porcelainShow the porcelain format with commit information for each line. Implies --porcelain.
--incrementalShow the result incrementally in a format designed for machine consumption.
--encoding=<encoding>Specifies the encoding used for outputting author names and commit summaries.
--contents <file>Annotate using the contents from the specified file. Can read from standard input with -.
--date <format>Specifies the format used to output dates.
--[no-]progressEnable or disable progress reporting. Cannot be used with --porcelain or --incremental.
-M[<num>]Detect moved or copied lines within a file. <num> specifies the minimum number of alphanumeric characters for detection (default: 20).
-C[<num>]Detect moved or copied lines between files. Can be specified multiple times. <num> specifies the minimum number of alphanumeric characters for detection (default: 40).
--ignore-rev <rev>Ignore changes made by the specified revision when assigning blame. Can be specified multiple times.
--ignore-revs-file <file>Ignore revisions listed in the specified file. Can be repeated.
--color-linesColor line annotations differently if they come from the same commit as the preceding line.
--color-by-ageColor line annotations based on the age of the line.
-hShow help message.
-cUse the same output mode as git-annotate.
--score-debugInclude debugging information related to line movement between or within files.
-f, --show-nameShow the filename in the original commit.
-n, --show-numberShow the line number in the original commit.
-sSuppress the author name and timestamp from the output.
-e, --show-emailShow the author email instead of the author name. Controlled by blame.showEmail config option.
-wIgnore whitespace when comparing the parent’s version and the child’s.
--abbrev=<n>Use the specified number of hexadecimal digits for abbreviated object names.




Examples

1. Blame a Specific File

To see who modified each line of a specific file, simply run:

$ git blame example.txt

This will display the author, date, and commit hash for each line in example.txt.

2. Blame a Specific Line Range

If you only want to see who modified a specific range of lines in a file, you can use the -L option:

$ git blame -L 10,20 example.txt

This will display the blame information for lines 10 to 20 in example.txt.

3. Blame with Additional Options

You can also use the -c, -w, and -M options to customize the output:

  • -c: Displays the original commit for lines that have been moved or copied.
  • -w: Ignores changes in whitespace.
  • -M: Detects lines that have been moved within a file.

For example, to blame a file and ignore whitespace changes:

$ git blame -w example.txt

This will display the blame information for example.txt, ignoring any changes in whitespace.

Scroll to Top