git-blame
Show who modified each line of a file
TLDR
Print file with author name and commit hash on each line
Print file with author email and commit hash on each line
Print file with author name and commit hash on each line at a specific commit
Print file with author name and commit hash on each line before a specific commit
Print author name and commit hash information for a specific line range
Ignore whitespaces and line moves
SYNOPSIS
git blame [options]
PARAMETERS
-b
Show blank SHA-1 object names as '0000000' instead of aborting.
-c
Show the original revision when the line was first added.
-l
Show long commit SHA-1 object names.
-t
Show the raw commit timestamp.
-e
Show the author email instead of author name.
-f
Show the filename in the original commit.
-n
Show the line number in the original commit.
-s
Suppress the author name and timestamp. Displays only the commit hash and line content.
-L
Limit blame output to the specified line range.
-S
Use revisions from
--contents
Blame
--reverse
Blame the specified range of revisions in reverse order.
The file to blame.
DESCRIPTION
The git blame command is a powerful tool used to examine the history of a file and discover when each line was last modified and by whom. It shows, for each line in the specified file, which revision last modified the line and who was the author of that change. This information can be invaluable for understanding code ownership, tracing bugs, and understanding the evolution of a codebase.
The output includes the commit hash, author, timestamp, and the line content itself. By default, blame operates on the current version of the file in the working directory. However, you can specify a particular revision or range of revisions to examine the history within a specific timeframe. It's a fundamental tool for developers collaborating on projects managed with Git, facilitating effective code review and debugging. The command's detailed output helps unravel the complexities of code modifications, enabling users to understand the reasons behind specific changes and the individuals responsible.
CAVEATS
Git blame only shows the last time a line was changed, not necessarily the original author of that line. If a line has been moved or copied from elsewhere, the blame will only point to the commit where it was moved/copied. To find the original author, you may need to use the `-C` option to trace across commits.
IGNORING COMMITS
You can configure git blame to ignore specific commits. This is useful if you have commits that make purely cosmetic changes (e.g., formatting) and you want to see the history before those changes. This can be configured in the .git-blame-ignore-revs file.
USING WITH GUI TOOLS
Many Git GUI clients provide visual interfaces for git blame, often called 'annotation' or 'history' views. These tools present the blame information in an interactive way, making it easier to navigate and understand the code's history.
HISTORY
git blame is a core Git command developed alongside Git itself. Its primary purpose has remained consistent: to trace the history of individual lines within a file. Over time, various options have been added to enhance its functionality, such as filtering by line range, displaying raw timestamps, and controlling the output format. It's widely used in software development workflows and remains a crucial command for code auditing and debugging.
SEE ALSO
git log(1), git diff(1)